I've looked around for this, and can't find an easily implemented solution.

Currently I'm working on an application that deals with panoramas. As they come out of the batch stitch process, the dimensions average 18000x4000. Using ImageMagick, how can I downscale those images to a specific height value while maintaining aspect ratio?

According to the manual, the convert operation takes in both height and width to resize to while maintaining the same aspect ratio. What I'd like is to put in 600 and 1000 in my existing resize script function and have both a regular viewable image as well as a reduced size.

  • IIRC it uses the smaller dimension as base for the resize operation, i.e. if you specify something like 20000x600 it will use the 600 height as the base to calculate the converted width so it maintains the aspect ratio. Did I made myself clear? – devius May 30 '12 at 12:07
  • Does it need to be ImageMagick? Phatch commands can be scripted, the 'fit' command does exactly what you're looking for. photobatch.wikidot.com/action-fit – Veazer May 30 '12 at 12:08

According to the documentation of ImageMagick I suggest to use -geometry x600, whereas x600 means that the new image has a heigth of 600 px with the same aspect ratio as the old image.

For a single image you could run:

convert input.png -geometry x600 output.png

If you prefer to convert all images of a folder in one run, switch to it (i.e. cd ~/Pictures/panoramas/) and use

mogrify -geometry x600 *.png

But be careful with that, because it overwrites the original image files. To avoid that you could

  1. create a new folder (mkdir ~/Pictures/panoramas/small)
  2. copy the images into this folder (cp ~/Pictures/panoramas/*.png ~/Pictures/panoramas/small) and
  3. edit the images in this new folder (cd ~/Pictures/panoramas/small && mogrify -geometry x600 *.png).

to resize all files in a folder, can use something like

mogrify -resize 800x1094! *jpg # keep image aspect ratio

--- change size and extension as suitable

  • 1
    This does not maintain the aspect ratio of the source image – Rob Jan 1 '15 at 20:01
  • 1
    @Rob if you want to keep aspect ration leave the "!" out. – Erick Feb 28 '17 at 8:01
  • Thanks @Erick, it's pretty old but I was likely pointing out that this answer doesn't answer correctly as the OP wanted to retain the aspect ratio. :D – Rob Feb 28 '17 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.