Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resize image only if width exceeds with Graphics/Image Magick

As seen here: http://www.imagemagick.org/Usage/resize/#shrink the option:

-resize 64x64>

only resizes if width and height exceeds 64 px. But how about to do something like that if works:

-resize 64>x

or

-resize 64x'ignores'>

in other words if only width exceeds this size. Is this possible?

like image 506
Luccas Avatar asked Jan 27 '26 23:01

Luccas


1 Answers

You can easily achieve that by using an 'unlikely large' height value:

convert  orig.png  -resize '64x10000>'  scaled.png

This will resize the original PNG only if its width was larger than 64 pixels or if its height is larger than 10 000 pixels. But the chance that the command will ever encounter an input that's higher than 10 000 pixels is very low. So it will (almost) only encounter input files where the width value matches.

Original PNGs with widths lower than 64 pixels will remain untouched (unless their height is above 10 000 pixels...).

like image 191
Kurt Pfeifle Avatar answered Jan 30 '26 16:01

Kurt Pfeifle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!