Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to compress and optimize Pictures in php

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly shows you "how to compress and optimize pictures in php". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn about "how to compress and optimize pictures in php".

The details are as follows:

Find a compressed image program written by php, which can be compressed in 10 levels (0-9). When the compression ratio is 0, the image will not be distorted; as the compression level increases, the picture will become less and less clear. usually, the image size can be reduced to 50% after compression, and the compression ratio is still quite large.

The following is the php image compression program

The volume of the original image is 125k, and now I want to see what kind of result I can get under different levels of compression. The following is the 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.6 K

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 it gets bigger when the compression level is 0.

When we optimize, it is generally appropriate to use level 2. The image is not distorted, but the volume is reduced by 30%, which achieves the purpose of optimization. If you use 6, 7, 8, 9 levels of compression, the picture is distorted, so it is not appropriate to use these levels to compress and optimize the picture.

Let's see 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.

Does the foreigner's explanation make sense? He believes that the original image is actually slightly compressed, while zero-level compression means that there is no compression at all, so it will be larger than the original image. I think there is some truth in this remark.

The above is all the contents of the article "how to compress and optimize pictures in php". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report