ImageMagick resize - setting the width for both landscape and portrait images

I'm trying to resize images to a given width , with the height adjusting proportionally - whether the image is in landscape or portrait orientation.

I have two images. I am testing the ImageMagick command convert -resize

with and from what I read, I would expect the following to work for any image:

convert source.jpg -resize 200 out.jpg

The problem is, no. Here are my results:

  • Original image 1: landscape

    , 3264 × 2448

    , resizes to 200 × 150

    ==> WORK
  • The original image 2: portrait

    , 3240 × 4320

    , resizes to 150 × 200

    ==> the FAIL

Now I know I can fix this by first reading the dimensions of the original image and making adjustments to the command (for example, using x200 for portrait seems to set the width to 200 correctly), but I can't help but think there must be a way to enable ImageMagick.

I was reading the documentation and looking for answers to the queries but can't seem to be able to solve it. Any help is appreciated.

EDIT:

I tried the following variation but I get the same incorrect result:

convert source.jpg -resize 200x out.jpg

FIX

convert source.jpg -auto-orient -resize 200 out.jpg

+3


source to share


2 answers


As discussed in the comments on JWK's answer:

The images appear to be a landscape instead of a portrait. Some image display applications read additional information from the exif profile of the image to determine the orientation. This caused some confusion because ImageMagick does not automatically use the exif profile information. This can be enforced with the auto-orient option. The command should be changed as follows:



convert source.jpg -auto-orient -resize 200x out.jpg

      

200x can also be written as 200, but using 200x or x200 is better if the width or height needs to be changed.

+5


source


I solved it. It turned out that the image information of my original portrait file was messed up in some way.

I ran the command identify portrait_source.jpg

and noticed that it has the wrong width and height ( 4320 x 3240

instead of 3240 × 4320

). Thus ImageMagick believed he was looking at a landscape file when it was indeed a portrait file. All other programs (OSX Finder, Preview) displayed the image in portrait orientation.



Simply opening the image in preview and saving it captured the image information and resizing after that worked as expected.

So, if you run into a problem like mine, be sure to check the image information in the original image. I have no idea why the information was wrong in the first place. I used a photo taken with a digital camera.

0


source







All Articles