Scaling images while preserving aspect ratio and placing on larger matrix in Max 9

djtoshi182's icon

I'm working on a project in Max 9 where I need to load large images of varying dimensions, scale them proportionally to fit within a fixed destination matrix (285x393), center them properly, and then place this resized image at a specific coordinate position (0, 687) on a larger canvas (1920x1080). I'm using float32 matrices for better image quality.

My specific workflow needs to:

1. Determine the shorter side of the original large image, as the source image can be portrait or landscape.

2. Scale the image so the shorter side matches the corresponding dimension of my destination matrix (285x393)

3. Center the resulting image so that the center of the image aligns with the center of the destination matrix

4. Place this resized image at x,y coordinate position (0, 687) on my larger 1920x1080 canvas

Thanks for your help.
Best,

J

Pedro Santos's icon

Hello! Does this help?

Max Patch
Copy patch and select New From Clipboard in Max.

djtoshi182's icon

Thank you for the patch. This finds the center in the destination matrix, but the image needs to be cropped or scaled to cover the destination area by matching the shorter side (width or height) of the image, while minimizing any reduction in quality. Images attached.

djtoshi182's icon

I am currently scaling variable-sized images (both portrait and landscape ratios) while preserving their proportions, but the resized images look low quality. Even using float32 instead of char and fsaa 1 doesn't prevent image quality reduction. What are the best ways to minimize image quality loss and scaling from the center of the image using this approach?

Max Patch
Copy patch and select New From Clipboard in Max.

thanks.

J

Herr Markant's icon

Hi J, this is how I keep the AR center.

Max Patch
Copy patch and select New From Clipboard in Max.

and here some images for testing:

testimages.zip
zip


Hope this helps.

Best Markus

djtoshi182's icon

Markus,

Thanks so much for the help with the patch. One quick question—how can I crop a scaled-down image from the center while keeping the image's original aspect ratio?