ImageMagick script to resize folder of images

℡╲_俬逩灬. 提交于 2019-12-11 12:54:53

问题


I have a folder of images of varying sizes and quality. Is there a way with ImageMagic that I could automatically resize them to be no bigger 1100px x 1100px and less than 160kb. And not to re-size if they are smaller than those parameters. Also not to distort the image so it fits within but to only re-size so for example an image which is 2200px by 1000px would become 1100px by 500px.

I'm working on Ubuntu with ImageMagick 6.7.7-10.


回答1:


Try this on a copy of your files:

mogrify -define jpeg:extent=160k -resize 1100x1100\> *.jpg

I am assuming your files are JPEG images. The command will largely work for other image types too, but it can only enforce the 160kB limit for JPEG files - not PNG, or TIFF etc.

Example

With version: ImageMagick 6.9.1-10 Q16 x86_64 2015-08-06

convert -size 2000x2000 xc:gray +noise random a.jpg

ls -lrt a.jpg
-rw-r--r--  1 mark  staff  6969601 21 Aug 18:28 a.jpg            # <--- 7MB

mogrify -define jpeg:extent=160k -resize 1100x1100\> a.jpg

ls -lrt a.jpg
-rw-r--r--  1 mark  staff  147938 21 Aug 18:28 a.jpg             # <--- 160kB

identify a.jpg
a.jpg JPEG 1100x1100 1100x1100+0+0 8-bit sRGB 148KB 0.000u 0:00.000


来源:https://stackoverflow.com/questions/32142042/imagemagick-script-to-resize-folder-of-images

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