imagemagickimage-resizingimagemagick-convertresize-imagemogrify

Can mogrify resize an image differently, depending on its orientation?


I have folders of images that I'd like to resize to either 3000x2000 or 2000x3000, depending on the orientation.

When I attempt to resize the images like this:

mogrify -path 'thumbnails' -resize 3000x2000 *.jpg

...The landscape images are correctly resized (3000x2000), but the portrait images are not (1333x2000). Is there any way to resize the images so that every image is either 3000x2000 or 2000x3000, depending on its orientation?

The source images could be in a variety of sizes and orientations (e.g. 5616x3744 or 3744x5616, 3321x5000 or 5000x3321, ...).

I'm trying to avoid distortion, so, if necessary, I'd prefer to have a slightly smaller image (3000x1998) over a larger image that is stretched.


Solution

  • This works!

    mogrify -path 'thumbnails' -resize '6000000@' *.jpg
    

    ...where 6000000 = 3000 x 2000 is the desired area of the image in pixels. Mogrify will scale the images down until they fit this maximum area, while preserving their original aspect ratio.

    Here's a link to the documentation for the geometry argument, in case you need to do something slightly different: https://imagemagick.org/script/command-line-processing.php#geometry

    I hope this helps!