gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 10:29:54 27 4
gpt4 key购买 nike

我正在尝试使用 Perl 中的 Imagemagick 在命令行上压缩图像(目前,我只能翻转它...)

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

图像必须压缩 50%,但 保持相同的尺寸 !我可以很好地调整图像大小,但如何像素化图像以降低分辨率,但保持相同的尺寸?

最佳答案

ImageMagick 提供了 -compress 开关,这可能会做你想要的。

-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.



检查这个例子/实验:
>>> 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

关于ImageMagick/Mogrify - 以编程方式压缩图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6331959/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com