ImageMagick脚本调整图像文件夹的大小 [英] ImageMagick script to resize folder of images

查看:311
本文介绍了ImageMagick脚本调整图像文件夹的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不同大小和质量的图像文件夹。有没有ImageMagic的方法,我可以自动调整它们大小1100px x 1100px和小于160kb。如果它们小于那些参数,则不要重新调整大小。也不要扭曲图像,使其适合但仅重新调整尺寸,例如2200px×1000px的图像将变为1100px×500px。

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.

我是使用ImageMagick 6.7.7-10在Ubuntu上工作。

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

推荐答案

在你的文件副本上试试这个:

Try this on a copy of your files:

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

我假设您的文件是JPEG图像。该命令也将主要用于其他图像类型,但它只能强制执行JPEG文件的160kB限制 - 不是PNG或TIFF等。

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.

示例

版本:ImageMagick 6.9.1-10 Q16 x86_64 2015-08-06

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

这篇关于ImageMagick脚本调整图像文件夹的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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