views:

183

answers:

2

I'm using ImageMagick's convert tool to generate image thumbnails for a web application. I'm using notation like so: 600x600>

The images are indeed scaled to 600px wide/tall (depending on the longer side) and proportions are properly maintained, however images less than 600px in either direction are scaled up — this behavior is not desired. Is there a way to prevent convert from scaling images up if the destination dimensions both exceed the original image size?

A: 

Look at the widthxheight> syntax

widthxheight> Change as per widthxheight but only if an image dimension exceeds a specified dimension.

Examples:

[/tmp]# identify -format "%wx%h"  test.gif
172x66 
[/tmp]# convert test.gif -resize '1000x1000>' test2.gif && identify -format "%wx%h"  test2.gif
172x66
[/tmp]# convert test.gif -resize '10x10>' test3.gif && identify -format "%wx%h"  test3.gif
10x4 
[/tmp]# convert test.gif -resize '100x100>' test4.gif && identify -format "%wx%h"  test4.gif
100x38 
leonbloy
Yep, using that already — `600x600>`
Kyle
To clarify: what do you want to happen for a 100x200 image and for a 100x700 image ?
leonbloy
+2  A: 

convert input.png -resize 600x600\> output.png does indeed work on my installation of ImageMagick. I would double check that the > is being escaped properly and that my version of ImageMagick is recent.

erjiang