I'm trying to get images resized to a given width, with the height being adjusted proportionally - no matter if the image has landscape or portrait orientation.
I have two images I test the ImageMagick convert -resize
command with and from what I have read, I would expect the following to work for any kind of image:
convert source.jpg -resize 200 out.jpg
The problem is, it doesn't. Here are my results:
- Source Image 1:
landscape
,3264 × 2448
, resizes to200 × 150
==> WORKS - Source Image 2:
portrait
,3240 × 4320
, resizes to150 × 200
==> FAIL
Now, I know I could fix this by reading in the source image dimensions beforehand and making adjustments to the command (e.g. using x200 for portrait seems to set the width correctly to 200) but I can't help but think that there must be a way to let ImageMagick handle this.
I read the documentation and googled for answers but cannot seem to solve this. Any help is greatly appreciated.
EDIT:
I have tried the following variation but get the same incorrect result:
convert source.jpg -resize 200x out.jpg
FIX:
convert source.jpg -auto-orient -resize 200 out.jpg