ImageMagick change aspect ratio without scaling the image

妖精的绣舞 提交于 2019-12-21 04:17:10

问题


I have a large number of images that can be any dimension that I need make into the same aspect ratio (basically square). So if one image is 100x300 the output should be 300x300. What I don't want is the image scaled or stretched in any way. I just want a background color (white) applied to the sides of the image, then the original image centered (either vertically or horizontally depending on the original aspect ratio).

I've played around with a couple different convert commands, but I have not found the magic one yet - they all either distort the image to reach the aspect ratio, or scale the image to the correct larger dimension, but do not have the aspect ratio I was looking for.

Thanks in advance


回答1:


convert input.png -background white -gravity center -extent 100x300 -flatten output.png

See http://www.imagemagick.org/Usage/crop/#extent



来源:https://stackoverflow.com/questions/5518561/imagemagick-change-aspect-ratio-without-scaling-the-image

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