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

标签 image command-line compression imagemagick

我正在尝试使用 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/

相关文章:

algorithm - 在哪里可以找到产生 headless 输出的无损压缩算法?

embedded - zlib 内存使用/性能。具有 500kb 数据

javascript - jQuery 幻灯片

android - HeifDecoderImpl 导致 'decStrong() called too many times'

c - 如何在 C 中使用 va_list 遍历命令行参数

svn - TortoiseSVN 命令行差异

css - SASS/SCSS 的@if 用于选择要使用的图像类型?

c# - 如何在运行时在 Xamarin.Forms 中动态更改图像的位置(x 和 y)?

command-line - Angular cli npm 启动失败

c++ - 需要一些关于 C++ 中简单无损压缩算法的想法