PHP + Imagick - PNG压缩 [英] PHP+Imagick - PNG Compression

查看:1780
本文介绍了PHP + Imagick - PNG压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何有效地压缩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屋!

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