ImageMagick/Mogrify-以编程方式压缩图像

I'm trying to compress an image on the command line using Imagemagick in Perl (currently, I'm only able to flip it...)

system("/usr/bin/mogrify", "-flip","/var/www/images/$pid-$count.jpg");

The image must be compressed in size by 50%, but retain the same dimensions! I can resize an image fine, but how to pixelate the image to lower the resolution, but keep the same dimensions?

#0

ImageMagick provides the -compress switch, which might do what you want.

-compress: Use pixel compression specified by type when writing the image

Choices are: None, BZip, Fax, Group4, JPEG, JPEG2000, Lossless, LZW, RLE or Zip.

To print a complete list of compression types, use -list compress.

Specify +compress to store the binary image in an uncompressed format. The default is the compression type of the specified image file.

If LZW compression is specified but LZW compression has not been enabled, the image data is written in an uncompressed LZW format that can be read by LZW decoders. This may result in larger-than-expected GIF files.

Lossless refers to lossless JPEG, which is only available if the JPEG library has been patched to support it. Use of lossless JPEG is generally not recommended.

Use the -quality option to set the compression level to be used by JPEG, PNG, MIFF, and MPEG encoders. Use the -sampling-factor option to set the sampling factor to be used by JPEG, MPEG, and YUV encoders for down-sampling the chroma channels.


check this example/experiment:

>>> du data/lena.png 
464K    data/lena.png
>>> cp data/lena.png .
>>> convert lena.png lena.jpg
>>> du lena.jpg 
76K lena.jpg           # already a lot smaller by going png --> jpeg
>>> mogrify -compress JPEG -quality 5 lena.jpg
>>> du lena.jpg 
8.0K    lena.jpg       # well, it did compress a lot and it's still viewable

推荐文章

如何在数据库中插入地质点值?

如何在数据库中插入地质点值?

推荐文章

Android回调-这是潜在的内存泄漏吗?

Android回调-这是潜在的内存泄漏吗?

推荐文章

.net中的母版页

.net中的母版页

推荐文章

C++ STL标准有什么变化吗?

C++ STL标准有什么变化吗?

推荐文章

发送陷阱时出现“错误版本或解码错误”

发送陷阱时出现“错误版本或解码错误”

推荐文章

Struts到servlet或将Struts和servlet集成

Struts到servlet或将Struts和servlet集成

推荐文章

JQuery自动完成选择组件?

JQuery自动完成选择组件?

推荐文章

如何用CGPoint数组画线

如何用CGPoint数组画线

推荐文章

如何使用OS4.0访问iPhone通用辅助功能设置

如何使用OS4.0访问iPhone通用辅助功能设置

推荐文章

更新的php日期

更新的php日期

推荐文章

如何计算与此查询中的字符串文本匹配的数据数?

如何计算与此查询中的字符串文本匹配的数据数?

推荐文章

jQuery Mobile:AJAX响应只嵌入第一个

jQuery Mobile:AJAX响应只嵌入第一个

推荐文章

为什么这个regex会失败?

为什么这个regex会失败?

推荐文章

如何修复此致命异常?

如何修复此致命异常?

推荐文章

按时间间隔测试代码

按时间间隔测试代码

推荐文章

如何从控制器获取数据以查看?

如何从控制器获取数据以查看?