Imagemagick 调整大小

Imagemagick 调整大小

我熟悉convert -resize %按百分比减小尺寸,但是将图像从 700 像素增加到 800 像素的命令是什么?水平宽度也应该调整大小。我需要尽可能保持图像的整体质量和外观。

编辑:

mogrify -resize geometry

这似乎是我调整图像大小所需的。 关联为下一个人尝试找出如何调整大小的文章。

答案1

ImageMagic 选项的convert具有-resize一个geometry参数强大的语法(见下文)来表达新旧图像尺寸所需的关系。

要将一个维度的大小调整为明确的值,并按相同因子调整另一个维度的大小,同时保持纵横比,您可以省略正常格式规范中的值之一,950x700如下所示:950用于指定宽度或x700高度。

convert in.jpg -resize x700 out.jpg

应该做你需要的。

为了获得最佳输出,最大的因素应该是重新压缩图像。如果输出 JPEG 图像,即使使用相同的压缩选项和相同的软件,它的压缩方式也与以前略有不同(否则,差异可能更大)。

与许多其他软件不同,默认值-resize非常好。你最好不要打扰他们。

对于影响调整大小的过滤步骤的微调选项,我不同意@peterph的答案,我认为这不会有助于尝试这些选项-filter-define filter:support=...

你可以破坏很多东西,但很难说到底是什么改变了。
以最佳方式调整大小和过滤涉及的数学比预期的要多得多,因此除非您拥有数学硕士学位,否则我建议不要调整调整大小选项。 (但请注意,这在其他地方可能是个好主意:我见过 Adob​​e 犯了错误。)

我以为我们谈论的是摄影图片,​​即用现实世界的物理相机拍摄的照片。
如果是其他内容,例如线条绘制或 3D 图形场景,“正确”的大小调整可能不是您所需要的;对于某些情况,可能有特殊的方法来调整大小。



-resize geometry, from 的参数语法www.imagemagick.org:

size               General description (actual behavior can vary for different options and settings)

scale%             Height and width both scaled by specified percentage.
scale-x%xscale-y%  Height and width individually scaled by specified percentages. (Only one % symbol needed.)
width              Width given, height automagically selected to preserve aspect ratio.
xheight            Height given, width automagically selected to preserve aspect ratio.
widthxheight       Maximum values of height and width given, aspect ratio preserved.
widthxheight^      Minimum values of width and height given, aspect ratio preserved.
widthxheight!      Width and height emphatically given, original aspect ratio ignored.
widthxheight>      Shrinks an image with dimension(s) larger than the corresponding width and/or height argument(s).
widthxheight<      Enlarges an image with dimension(s) smaller than the corresponding width and/or height argument(s).
area@              Resize image to have specified area in pixels. Aspect ratio is preserved.

答案2

convert -resize $((800/7))%

或者

convert -resize 114.28571%

会调整大小。至于控制图像质量,您可能需要检查-filter-support选项。

相关内容