1
votes

I'm trying to reduce the resolution of a large number of images using ImageMagick. The photos' original size is 5312 x 2988 pixels. The new dimensions should be 2000 x 1125 px.

Here is the command I'm using:

mogrify -path "C:\Users\Joe\Desktop\img\new" -resize 2000x1125 -auto-orient -format jpg -quality 75 "C:\Users\Joe\Desktop\img\*.jpg"

It works great for images that are in landscape mode. The problem is for images that are in portrait mode, with a resolution of 2988 x 5312 px. When I run the above command, their resulting size is 633 x 1125 px instead of 1125 x 2000.

Which command can I run that will produce, if the original image is 5312 x 2988, a resulting image of 2000 x 1125 (landscape). Or, if the original image is 2988 x 5312 (portrait), a resulting image of 1125 x 2000 pixels? It should be a single command since I have large number of images in a folder in both landscape and portrait modes.

Basically, the largest dimension should be 2000. If the photo is in landscape, the width should be 2000 px and the height should scale down proportionately. If the photo is in portrait mode, the height instead should be 2000 px.

1
I think I understood. Make a copy somewhere separate and try with simply -resize 2000 so the longest side comes out at 2000.Mark Setchell
That was it! If you would like to submit your response as an answer, I'll accept it. Also note: I needed to move the -auto-orient flag AFTER -resize, so that the resize happens regardless of the orientation mode.GTS Joe
Glad it worked for you. Please write it up yourself as you have tested and checked it all out - then you can accept your own answer and bag the points.Mark Setchell

1 Answers

0
votes

The answer, as Mark suggested, ended up being using the -resize flag with only one parameter, e.g.: -resize 2000. When only one parameter is specified, the longest side will be 2000 (the other dimension will be scaled automatically and proportionately).

The caveat was, if you're using the -auto-orient flag in the same command, make sure to place -auto-orient AFTER -resize. That way, ImageMagick disregards image orientation when resizing.

mogrify -path "C:\Users\Joe\Desktop\Folder\New" -resize 2000 -format jpg -quality 75 -auto-orient "C:\Users\Joe\Desktop\Folder\*.jpg"

The key being calling -resize BEFORE -auto-orient.