Why is the same picture png smaller than jpg?

PNG format related introduction:

1. The size of the png format is small, and it is restricted by the bandwidth in the network communication , which ensures the clarity of the picture.

2. The PNG file is compressed by the LZ77 algorithm , which can obtain a high compression ratio without data loss.

3. It uses special coding to mark the data that appears, and it has no effect on the color of the image and will not lose it.

4. It also optimizes the display of network transmission. PNG images are all streamed in the browser, so they can be output continuously.

The root cause is that the compression algorithm and packaging method are different.

Even if PNG is a lossless format , JPEG quality 100% can also be regarded as a lossless format; even if PNG does not support embedded ICC color profiles when exported in Photoshop but JEPG does; even if PNG supports transparency and JPEG does not support transparency - these are not conclusive of.

We assume that before A is stored, the amount of information to be put in the A.jpg file and the A.png file is the same, then after being packaged into jpg and png with different algorithms, the size will be different. Because they are all compressed, compression and lossless are not in conflict, compression only means that they need to be decompressed when reading, but the compression algorithm is different.

Take another simple example. If you have a text file B, after compressing it into B.rar, B.zip and B.7z, the sizes of the three are almost bound to be different. The three compressed files all completely retain all the information of the text file B, the difference lies in the compression algorithm. For compression software , the possible differences between the compression algorithm and the packaging method may lie in:

  • The file headers are different (package problem)
  • Additional configuration files (packaging issues, such as text encoding support, etc.)
  • The logic of extracting the dictionary is unreasonable (compression algorithm problem, such as text such as abcdabcd, algorithm 1 may extract abcd from the knife dictionary, and algorithm 2 may extract ab and cd into the dictionary respectively)
  • Differences in the number of dictionary layers (compression algorithm issues, for example, algorithm 1 may extract the dictionary once and end, while algorithm 2 may compress the dictionary extracted for the first time as the text, generate a 2-level dictionary and attach an additional file header indicating that there is 2 layers of dictionaries)

The compression and packaging of image formats is applicable to the same principle as the compressed files mentioned above. In general, PNG has more advantages in storing images with fewer colors.

Guess you like

Origin blog.csdn.net/m0_67948827/article/details/128466278