Imagemagick:转换为固定高度,比例宽度

Chr*_*ian 34 image imagemagick

使用Imagemagick,我想要convert一批PNG到1080px的固定高度和比例宽度.用比例我的意思是这样的:如果原始图像被按比例缩小16.8%至1080px,宽度也需要16.8%按比例缩小.

任何使用转换的方式,而不必计算之前的精确几何(使用identify和一些bash计算shenanigans)?

小智 67

试试这个:

convert -resize x1080 {from_path} {to_path}
Run Code Online (Sandbox Code Playgroud)


Dan*_*elB 6

图像几何是描述使用的选项-resize

xheight Height given, width automagically selected to preserve aspect ratio.
Run Code Online (Sandbox Code Playgroud)

所以你只需要指定高度


And*_*Rae -1

还有一个额外的例子。给它一些调整大小参数的值,它会自动调整图像的大小。另外,您可以选择其他参数(重心或作物等)。

  convert image_example: \
          -resize x160 -resize '160x<'   -resize 50% \
          -gravity center  -crop 80x80+0+0 +repage  image_example.jpg
Run Code Online (Sandbox Code Playgroud)

干杯