Resize and crop image in single operation

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
wardrop
Posts: 5
Joined: 2014-02-09T17:10:27-07:00
Authentication code: 6789

Resize and crop image in single operation

Post by wardrop »

Hi,

I'm trying to resize and crop an image using `mogrify`, but it seems the version of ImageMagick I'm using crops BEFORE resizing. Here's the command I'm using:

Code: Select all

mogrify -format jpg -colorspace RGB  -resize "160x160^" -gravity center -crop 160x160+0+0 /tmp/input.jpg
On my computer running ImageMagick 6.7.7-6, the above works fine. The image is resized so the smallest dimension is 160 pixels, and it then crops the result. However, on the server I'm deploying to which runs ImageMagick 6.4.3, the operation happens in reverse. The image is cropped first, which obviously produces the wrong result.

If I pass the same parameters to `convert`, it produces the correct result on both versions:

Code: Select all

convert -format jpg -colorspace RGB  -resize "160x160^" -gravity center -crop 160x160+0+0 /tmp/input.jpg /tmp/output.jpg
However, I need to make this work using `mogrify` as that what the library I'm using uses in the background. Can anyone tell me how to get the desired result on the slightly older version of ImageMagick running on our production server?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resize and crop image in single operation

Post by fmw42 »

Works fine on 6.8.8.5 Q16. My guess is that the ^ symbol was not introduced until after 6.4.3

Checking the changelog, I see ^ was introduced at 6.3.8-2

So I guess it is a bug in 6.4.3
Post Reply