PHP compression techniques introduce _php picture function - PHP

Source: Hi learning network sensitive and eager Forum www.piaodoo.com welcome to learn from each other

php application development often involves generating thumbnails generate thumbnails using the php process itself is not difficult, but you know php can adjust to optimize the quality of the generated thumbnails do? That is possible to control the creation of thumbnails php clarity, and the volume of the generated thumbnails. Here we look at how to use php to optimize the picture after our compression.

How to use php to generate thumbnails not presented here, we can refer to the site the following article: PHP source code examples function to automatically generate thumbnails

First we look at code compression pictures with php:

? <PHP 
header ( 'Content-of the type: Image / PNG'); 
$ Image = @ imagecreatefrompng ( '// www.jb51.net/test.png'); 
imagepng ($ Image, 'test.png', 0) ; // Note that behind the numbers 0, where the level of compression that is, the range of parameters: * 0-9 / 
imagedestroy ($ Image); 
>?

The third argument over imagepng function that is to be analyzed in this article, the meaning of this parameter is to generate the picture quality level. Here can be divided into 10 grades (0-9), ie uncompressed zero level, the picture will not be distorted, the clearest picture, but the picture is also the largest volume, with digital compression level is increasing, the picture will become increasingly the less clear, but the volume of compressed images can be reduced to the original 50%, the compression ratio is still getting bigger.

Let's look at a particular example of it, is now a 125K original volume, the following is the test result through different compression levels:

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

Note that the above time when the compression level is 0, the volume is bigger than the original because the original picture actually is the result of a slight compression, and compression level 0 is not compressed a little, so it's volume will be larger than the original picture.

The above results and the actual test results concluded that when the image optimization, the general level of 2 is appropriate, no image distortion, but the volume was reduced by 30%, to achieve the optimization purposes. If 6,7,8,9 level compression, then, the picture has been distorted, and the volume reduction is not obvious. So these grades should not be used to compress image optimization.

to sum up

That's all for this article, I hope the contents of this paper has some reference value of learning for all of us to learn or work, thank you for the support sensitive and eager Forum / Hi learning network. If you want to know more details, please see the related links below

The original address is: http: //www.piaodoo.com/thread-3548-1-1.html

Guess you like

Origin www.cnblogs.com/txdah/p/12093295.html
php