-resize> faulty behavior

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Wouter
Posts: 2
Joined: 2013-11-29T03:16:10-07:00
Authentication code: 6789

-resize> faulty behavior

Post by Wouter »

The resize function shows unexpected behavior in the following case:

The following command should resize an image to fit within 1200x1200, keep the aspect ratio and also ignore images that are smaller (so only downsize, hence the ^>, ^ since I work on a Windows machine).

Code: Select all

convert -resize 1200x1200^> source.jpg target.jpg
My source image is 1920x1080, I would expect it to be turned into 1200x675, but instead it stays the original resolution. After some testing I found that the reason it does this is because it tries to keep the aspect ratio, so because 1080 is within 1200, it ignores the 1920 size.

I ran the command again without the ^> part.

Code: Select all

convert -resize 1200x1200 source.jpg target.jpg
In this case it is processed correctly and the target image is 1200x675. However, since I removed the ^> part it will now also start to upscale images that are smaller than 1200x1200.

So in short, the setting used to force "downscale only", has the unexpected side-effect that it will also keep the aspect ratio by taking the smallest side and use that to fit the bounding box of 1200x1200, instead of the normal behavior where it would try to fit the largest side of the image and make sure that that fits within the bounding box of 1200x1200.

I would consider this a bug, but maybe I don't understand the settings of -resize in enough detail.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: -resize> faulty behavior

Post by fmw42 »

^ is also a resize flag as well as an escape in windows. I am not a windows user, but I might guess that there may be confusion. Try putting double quotes around it and leave off the ^ escape.

convert -resize "1200x1200>" source.jpg target.jpg


If that does not work, then one of the windows users may be able to give more accurate advice.

But please provide your IM version and platform information about Windows OS

On my Mac OS IM 6.8.7.8 Q16, I get the right behavior.

convert -size 1920x1080 xc:red tmp.png

convert tmp.png -resize 1200x1200\> tmp2.png

identify tmp2.png
tmp2.png PNG 1200x675 1200x675+0+0 8-bit sRGB 2c 367B 0.000u 0:00.000


convert tmp.png -resize "1200x1200>" tmp3.png
identify tmp3.png
tmp3.png PNG 1200x675 1200x675+0+0 8-bit sRGB 2c 367B 0.000u 0:00.000
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: -resize> faulty behavior

Post by snibgo »

Window 7, IM 6.8.7:

Code: Select all

convert -size 192x108 xc: -resize 1200x1200^> o.png
This works as it should for me. Note the "-resize" is after, not before, the input file.
snibgo's IM pages: im.snibgo.com
Post Reply