PHP + Imagick - PNG压缩 [英] PHP+Imagick - PNG Compression
问题描述
如何有效地压缩PNG?
目前我在玩这个游戏:
// ...
$ im-> setImageFormat('png');
$ im-> setImageColorspace(\Imagick :: COLORSPACE_GRAY);
$ im-> setImageCompression(\Imagick :: COMPRESSION_LZW);
$ im-> setImageCompressionQuality(9);
$ im-> stripImage();
$ im-> writeImage($ url_t);
由于Imagick不提供 COMPRESSION_PNG
我试过LZW,但文件大小几乎没有变化(通常它比以前更大)。
如果我在GIMP中打开图像,只是保存它,文件大小大幅减少(例如11,341 B - > 3,763 B或11,057 B - > 3,538)。
使用Imagick保存压缩PNG的正确方法是什么?
查看此答案的第一部分:
它解释了ImageMagick的 -quality
设置对PNG的含义+语法。 / p>
How do I efficiently compress a PNG? In my case, the images are small grayscale images with transparency.
Currently I'm playing with this:
// ...
$im->setImageFormat('png');
$im->setImageColorspace(\Imagick::COLORSPACE_GRAY);
$im->setImageCompression(\Imagick::COMPRESSION_LZW);
$im->setImageCompressionQuality(9);
$im->stripImage();
$im->writeImage($url_t);
As Imagick doesn't offer COMPRESSION_PNG
, I've tried LZW but there's almost no change in the filesize (usually it's even bigger than before).
If I open the image in GIMP and simply save it, the filesize gets drastically reduced (e.g. 11,341 B --> 3,763 B or 11,057 B --> 3,538).
What is the correct way of saving a compressed PNG with Imagick?
Have a look at the first part of this answer:
It explains the meaning + syntax of ImageMagick's -quality
setting for PNGs.
这篇关于PHP + Imagick - PNG压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!