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:
landscape
, 3264 × 2448
, resizes to 200 × 150
==> WORKS
portrait
, 3240 × 4320
, resizes to 150 × 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
As discussed in the comments of the answer by JWK:
The images seem to be landscape instead of portrait. Some applications that show an image read extra information from the exif profile of the image to determine the orientation. This was causing some confusion because ImageMagick does not automatically use the information from the exif profile. This can be forced with the auto-orient option. The command should be changed to this:
convert source.jpg -auto-orient -resize 200x out.jpg
The 200x can also be written as 200 but using 200x or x200 shows better if the width or the height should be resized.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With