10 compression-optimized image operation examples in php with different levels,

Source: Internet
Author: User

10 compression-optimized image operation examples in php with different levels,

This article analyzes 10 different compression Optimization Image operations in php. We will share this with you for your reference. The details are as follows:

Today, I found a php compressed image program that can be compressed by 10 levels (0-9). The compression ratio is not very high when the 0 level is used, and the image will not be distorted; as the compression level increases, the image will become increasingly unclear. Generally, the size of the compressed image can be reduced to 50% of the original size, and the compression ratio is quite large.

The following is a php image compression program.

<? PhpHeader ("Content-type: image/PNG");/* Tell IE that your program is an image */$ image = @ imagecreatefrompng ("banner.png "); imagepng ($ image, null, 0);/* compression level 0-9, minimum 9 after compression, 1 Maximum */imagedestroy ($ image);?>

The size of the source image is 125 KB. Now I want to see what results will be obtained under different compression levels. The following is a test record.

Imagepng ($ img, null, 0); --> Size = 225 K
Imagepng ($ img, null, 1); --> Size = 85.9 K
Imagepng ($ img, null, 2); --> Size = 83.7 K
Imagepng ($ img, null, 3); --> Size = 80.9 K
Imagepng ($ img, null, 4); --> Size = 74.6 K
Imagepng ($ img, null, 5); --> Size = 73.8 K
Imagepng ($ img, null, 6); --> Size = 73 K
Imagepng ($ img, null, 7); --> Size = 72.4 K
Imagepng ($ img, null, 8); --> Size = 71 K
Imagepng ($ img, null, 9); --> Size = 70.6 K

What I don't understand is why the compression size increases when the compression level is 0?

When we optimize the image, it is generally appropriate to use 2 levels, the image is not distorted, but the volume is reduced by 30% to achieve the goal of optimization. If the image is compressed at levels 6, 7, 8, and 9, the image is distorted. Therefore, it is not recommended to use these levels to compress and optimize the image.

Let's 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 be larger than the original (that can be slightly compressed to begin with). You need to understand file compression and php gd image constructor.

Is there any reason for a foreigner's explanation? He believes that the original image is actually slightly compressed, and the 0-level compression means that there is no compression at all, so it will be larger than the original image. I don't think it makes sense.

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.