New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image compression not working on some png images. #29
Comments
You specified compression quality 70 and that's what you get. Try 75. The second digit of the quality means the PNG "filter method". Zero means no filtering, so for this image the compression is less effective. |
The uncompressed image is 3.4Mb so reducing it to 246.5kb isn't too bad for lossless compression. I ran your image through pngcrush and that was only able to reduce it by about 3kb, to 243.6kb. If you need a smaller file you'll have to do lossy compression instead. |
So does that mean changing setImageCompressionQuality parameter will have none or negligible effect on PNG images. Also its perfectly okay if instead of expecting reduction you get increase in file sizes on reducing this image quality parameter ? |
It doesn't mean that exactly. It means that if you set the image compression quality to something less effective than whatever was used to compress your original image, the file size might increase. It is perfectly OK for ImageMagick to obey your "-quality" setting, even if it results in a larger file. The default behavior, if you omit setting quality, is pretty good but not optimum. If you are concerned about squeezing out the last few bytes possible, use a third-party optimizer such as my "pngcrush" or any of a number of others that you can find on the net. |
In that case the image quality parameter is misleading or maybe not properly documented. Because i'm sure most of us assume that the quality setting is in reference to the already compressed image being fed and not the original uncompressed image. Anyways thanks for your time and valuable information you've shared. Also is there a source where I can read what the first and second parameters of this quality parameter mean for different image formats and what best combination compression algo(for example Imagick::COMPRESSION_ZIP) and quality setting i can use which works best for all image types for display on web ? |
It's explained in http://imagemagick.org/script/command-line-options.php#quality Just for PNG/MNG, it's also explained, as emcconville mentioned, in coders/png.c The quality is in reference to the image being written.
Glenn |
Hi @glennrp, It looks like the value that the PNG compression reads was changed from btw if you want to, you could tell PHP users to send issues at https://github.com/mkoppanen/imagick which is where the Imagick extension is maintained. @avdheshb you'll need to use the setCompressionQuality function rather than the setImageCompressionQuality function if you're using a version of ImageMagick where the change above is applied. Below is a simple brute force routine to test it's actually working.
|
But I found an effective way, that is use |
I'm trying to compress some images using below code. But instead of getting compressed it's size gets increased:-
This is the original image 246.3kB:-
And this is the image after running the code above( 314.2 kB ):-
However when i convert original image to jpg format using gimp and then run the code above then the results are as expected.
Below is some phpinfo():-
PHP Version 5.4.42
System : Linux server 2.6.32-504.12.2.el6.x86_64 #1 SMP Wed Mar 11 22:03:14 UTC 2015 x86_64
imagick module version : 3.1.2
ImageMagick version : 6.7.2-7 2015-07-23 Q16
Thanks,
Avdhesh
The text was updated successfully, but these errors were encountered: