如何防止ImageMagick的convert工具将图像放大?

4
我正在使用ImageMagick的convert工具为Web应用程序生成图像缩略图。我使用以下表示法:600x600> 图像确实被缩放为600像素宽/高(取决于较长的一侧),并且比例得到了正确维护,但是任何方向上小于600像素的图像都会被放大 - 这种行为是不希望的。是否有一种方法可以防止convert在目标尺寸超过原始图像尺寸时放大图像?

如果您的图像尺寸小于阈值,为什么需要通过ImageMagick运行它们并使用该参数?为什么不只是将它们转换过来,或者您需要所有图像都具有精确的尺寸? - KushalP
2个回答

2
"

convert input.png -resize 600x600\> output.png 的确在我的 ImageMagick 安装中有效。我会再次确认 > 是否已经得到正确转义,以及我的 ImageMagick 版本是否较新。

"

1

看一下 widthxheight> syntax

widthxheight> 根据需要更改为 widthxheight,但仅当图像尺寸超过指定尺寸时才更改。

示例:

[/tmp]# identify -format "%wx%h"  test.gif
172x66 
[/tmp]# convert test.gif -resize '1000x1000>' test2.gif && identify -format "%wx%h"  test2.gif
172x66
[/tmp]# convert test.gif -resize '10x10>' test3.gif && identify -format "%wx%h"  test3.gif
10x4 
[/tmp]# convert test.gif -resize '100x100>' test4.gif && identify -format "%wx%h"  test4.gif
100x38 

请澄清一下:您希望针对100x200像素和100x700像素的图片分别发生什么? - leonbloy

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接