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

痴心易碎 提交于 2019-12-05 02:41:24

问题


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?


回答1:


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...).



来源:https://stackoverflow.com/questions/12273203/how-to-resize-image-only-if-width-exceeds-with-graphics-image-magick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!