Imagemagick转换调整大小然后裁剪 [英] Imagemagick convert resize then crop

查看:429
本文介绍了Imagemagick转换调整大小然后裁剪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有1000幅不同分辨率的图像(例如1234x2122、4400x5212等),我想将它们全部转换为固定的100x100尺寸,所以。


  1. 首先,我需要按比例调整图像大小,并得到100xA或Ax100,其中A> 100(对于图像的宽度和高度,它取决于图像的宽度和高度,对于某些图像,宽度> height和一些图像的高度>宽度)。


  2. 将此图像从中心裁剪到100x100


是否有一个简单的convert命令,可以用于所有图像?

解决方案

您将使用区域填充 ^ -resize 操作上的-processing.php#geometry rel = noreferrer>几何修改器以统一缩小比例。要裁剪中心,请 -范围 -重力中心 将起作用。

 转换input.jpg-调整大小100x100 ^ \ 
-重力中心\
-范围100x100 \
output.jpg

更新



正如Mark Setchell在评论中指出的, mogrify 实用程序可以用来批量转换项目。

  mogrify -path ./path/to/write/results/ \ 
-调整大小100x100 ^ \
-重力中心\
-范围100x100 \
./path/to/source/files/*



< blockquote>

提醒: Mogrify将使用结果图像覆盖原始文件,除非您设置 -path 参数。




I have over 1000 images on different resolutions, (for example 1234x2122, 4400x5212 , etc) and I want to convert all them to fixed 100x100 size, so.

  1. first I need to resize images keeping proportions, and get 100xA or Ax100, where A > 100 ( it depends width and height of image, for some images width > height, and for some images height > width ).

  2. Crop this image to 100x100 from center

Is there a simple convert command, that I can use for all my images ?

解决方案

You would use the area-fill (^) geometry modifier on the -resize operation to unify the down-scale. For cropping the center, -extent with -gravity Center will work.

convert input.jpg -resize 100x100^ \
                  -gravity Center  \
                  -extent 100x100  \
        output.jpg

Update

As Mark Setchell pointed out in the comments, the mogrify utility can be leveraged to batch convert items.

mogrify -path ./path/to/write/results/ \
        -resize 100x100^ \
        -gravity Center  \
        -extent 100x100  \
        ./path/to/source/files/*

Reminder: Mogrify will overwrite original file with resulting image(s), unless you set the -path parameter.

这篇关于Imagemagick转换调整大小然后裁剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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