Today found a PHP write compressed picture program, can be divided into 10 levels (0-9) to compress, 0 grade when the compression ratio is not very large, the picture will not be distorted; As the compression level increases, the picture will become more and more unclear, usually compressed after the image size can be reduced to the original 50%, compression ratio is quite large.
The following is a PHP compressed picture program
<?php
Header ("Content-type:image/png");/* Tell IE your program is a picture */
$image = @imagecreatefrompng ("Banner.png");
Imagepng ($image, null,0); /* Compression level 0-9, 9 min after compression, 1 Max */
Imagedestroy ($image);
?>
The original volume is 125k, and now I want to see what the results will be at different levels of compression. The following is a Test record.
Imagepng ($img, null,0); --Size = 225K
Imagepng ($img, null,1); --Size = 85.9K
Imagepng ($img, null,2); --Size = 83.7K
Imagepng ($img, null,3); --Size = 80.9K
Imagepng ($img, null,4); --Size = 74.6K
Imagepng ($img, null,5); --Size = 73.8K
Imagepng ($img, null,6); --Size = 73K
Imagepng ($img, null,7); --Size = 72.4K
Imagepng ($img, null,8); --Size = 71K
Imagepng ($img, null,9); --Size = 70.6K
What I don't understand is why the compression level is 0 o'clock, and its volume is bigger?
When we optimize, the general use of 2 grade more appropriate, the picture is not distorted, but the volume reduced by 30%, to achieve the purpose of optimization. If the 6, 7, 8, 9 grade compression, the picture is distorted, so it is inappropriate to use these levels for compression optimization picture.
Let's see how the foreigner explains this phenomenon:
The result seems accurate since 0 means no compression
Quality Compression Level:from 0 (no Compression) to 9.
It's normal for the 0ed file to is larger than the original (that is, can slightly compressed to begin with). You need to understand file compression and PHP GD image constructor.
Is there any reason for the foreigner's explanation? He thinks the original picture is actually a slight compression, and the 0-level compression is not a bit of compression, so its volume will be larger than the original picture. I feel it is not unreasonable.
PHP 10 different levels of compression optimized image