仅使用ImageMagick缩小较大的图像比例 [英] Only shrink larger images using ImageMagick to a ratio

查看:284
本文介绍了仅使用ImageMagick缩小较大的图像比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用ImageMagick,我可以很容易地截取我想要的内容,但我想调整它以减少占用空间。我发现了这个:

Using ImageMagick, I can easily have a screenshot of what I want, but I'd like to resize it for using less space. I found this :

convert screen.jpg    -resize 1280x1024\!  screen.jpg

但我想根据最大尺寸(宽度或高度)调整尺寸并且另一个(高度或宽度)也将按比例调整大小。

But I'd like to resize it based on the most bigger size (width OR height) and the other one (height OR width) will be proportionnaly resized too.

例如,假设我希望我的所有图像的最大宽度调整为600px /身高:

For example, say I want all my image to be resized to 600px at their most width/height size :


  • 1920x1200 =>宽度最大:600x375

  • 600x1200 =>身高是最大的:300x600

我怎么能用ImageMagick做到这一点?
(或者至少,定义一个最大尺寸(例如只有宽度))。

How can I do that with ImageMagick? (or at least, defining one max size (only width for example)).

感谢您的帮助!

注意:是否可以使用 import 命令自动实现它?

Note: is it possible to implement it automatically with the import command?

推荐答案

要保留纵横比,您可以按一定比例缩小图像:

To preserve aspect ratio, you can shrink the image by a certain scale:


convert -resize 50% screen.jpg

convert -resize 50% screen.jpg

或使用像素区域:


convert -resize 180000 @ screen.jpg

convert -resize 180000@ screen.jpg

这也会将小图像炸成指定区域。如果您希望ImageMagick缩小大图像但保持小图像不变,请使用>运算符:

This would also blow up small images to the specified area. If you want ImageMagick to shrink your large images but keep small images untouched, use the ">" operator:


convert -resize'180000 @ >'screen.jpg

convert -resize '180000@>' screen.jpg

请注意,然后您需要引用geometry参数以防止shell解释>符号作为文件重定向器。

Note that you then need to quote the geometry argument in order to prevent your shell interpreting the ">" sign as a file redirectors.

有关这些和其他选项,请参阅ImageMagick文档: http://www.imagemagick.org/script/command-line-processing.php#geometry

See ImageMagick documentation for these and other options: http://www.imagemagick.org/script/command-line-processing.php#geometry

这篇关于仅使用ImageMagick缩小较大的图像比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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