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.
PHP 10 different levels of compression optimized image