PHP 10 different levels of compression optimized picture operation Example _php tips

Source: Internet
Author: User
Tags php write

This paper analyzes 10 different levels of compression optimized picture operation in PHP. Share to everyone for your reference, specific as follows:

Today find a PHP write compression picture program, can be divided into 10 levels (0-9) to compress, 0-level compression ratio is not very large, the picture will not be distorted; As the compression level continues to increase, the picture will become more and more unclear, usually compressed image size can be reduced to the original 50%, compression ratio is quite large.

The following is the PHP compression picture program

<?php
Header ("content-type:image/png");/* Tell IE browser that the program you are doing 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 happens 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 do not understand is why the compression level is 0 o'clock, and its volume becomes larger?

We are in the optimization, the general use of 2 grades more appropriate, the picture is not distorted, but the volume has been reduced by 30%, to achieve the purpose of optimization. If the use of 6, 7, 8, 9 grade compression, the picture is distorted, so it is inappropriate to use these levels for compression optimization pictures.

Let's take a look at how foreigners explain 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 can is slightly compressed to begin with). You are need to understand file compression and PHP GD image constructor.

Does the foreigner's explanation have any reason? He thought the original picture was actually a slight compression, and the 0-grade compression is not a bit of compression, so its volume will be larger than the original picture. I feel this is not unreasonable.

More about PHP Interested readers can view the site topics: "PHP graphics and pictures Operating skills summary", "PHP file Operation Summary", "PHP Array" operation Skills Encyclopedia, "PHP Basic Grammar Introductory Course", "PHP Operations and Operator Usage Summary", " Introduction to PHP object-oriented programming program, "PHP Network Programming Skills Summary", "PHP string (String) Usage Summary", "Php+mysql database Operation Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.