ImageMagick在不缩放图像的情况下更改宽高比 [英] ImageMagick change aspect ratio without scaling the image

查看:132
本文介绍了ImageMagick在不缩放图像的情况下更改宽高比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有大量的图像,可以是我需要的任何尺寸,以相同的宽高比(基本上是正方形)。因此,如果一个图像是100x300,则输出应为300x300。我不想要的是以任何方式缩放或拉伸的图像。我只想要一个背景颜色(白色)应用于图像的两侧,然后原始图像居中(垂直或水平取决于原始的宽高比)。

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.

提前致谢

推荐答案

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

请参阅 http://www.imagemagick.org/Usage/crop/#extent

这篇关于ImageMagick在不缩放图像的情况下更改宽高比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆