Imagemagick convert crop and resize

点点圈 提交于 2019-12-03 07:34:23

问题



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 ?


回答1:


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.


来源:https://stackoverflow.com/questions/32466048/imagemagick-convert-crop-and-resize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!