How to choose and use PNG, JPG, and GIF as web image formats

How to choose and use PNG, JPG, and GIF as web image formats

So which one of these formats, GIF, PNG, and JPG, should we choose as a candidate format, and which image format can make the image smaller but have better image quality?

1. Image Format

GIF

The most outstanding feature of GIF is that it supports animation. At the same time, GIF is also a lossless image format, which means that after you modify the image, the image quality is not lost. In addition, GIF supports semi-transparency (fully transparent or fully opaque).
According to Google, GIFs are suitable for very small or simple images (less than 10×10 or with less than 3 colors).

PNG

First of all, PNG includes PNG-8 and true color PNG (PNG-24 or PNG-32). The biggest advantages of PNG over GIF are:

  • Usually smaller in size
  • Support alpha (full transparency)

But we know that PNG does not support animation.

Also note that IE6 can support PNG-8, but will display gray when processing PNG-24 transparency. For related examples, please refer to sitepoint .

Generally, images saved as PNG-8 will be smaller than GIF at the same quality, and for fully transparent images we can only use PNG-24 now. But please be careful when saving images in PNG-8 and comparing them with GIF. Because the law is not always correct.

JPG

JPG can display more colors than GIF and PNG, and it is well compressed, so JPG is very suitable for saving digital photos. But please note that it is a lossy compression, which means that every time you modify the image, it will cause pixel distortion.

After reading the above introduction, you should have a general understanding of which format to use to save which image. In short:

Bottom line: For small images or basic web page elements (such as buttons), consider PNG-8 or GIF. For photos, consider JPG.

<<:  About vue component switching, dynamic components, component caching

>>:  Example code for hiding element scrollbars using CSS

Recommend

How to find identical files in Linux

As the computer is used, a lot of garbage will be...

Sharing experience on the priority of CSS style loading

During the project development yesterday, I encoun...

The url value of the src or css background image is the base64 encoded code

You may have noticed that the src or CSS backgroun...

How to store images in MySQL

1 Introduction When designing a database, it is i...

Example code for implementing stacked carousel effect with HTML+CSS+JS

Effect: When the slideshow moves in one direction...

Example code and method of storing arrays in mysql

In many cases, arrays are often used when writing...

How to simulate network packet loss and delay in Linux

netem and tc: netem is a network simulation modul...

Summary of the use of html meta tags (recommended)

Meta tag function The META tag is a key tag in th...

Basic usage and pitfalls of JavaScript array sort() method

Preface In daily code development, there are many...

Detailed explanation of the group by statement in MySQL database group query

1: Statement order of grouping function 1 SELECT ...

MySQL 5.7.19 winx64 free installation version configuration tutorial

mysql-5.7.19-winx64 installation-free version con...

How to configure Linux to use LDAP user authentication

I am using LDAP user management implemented in Ce...

How to configure mysql5.6 to support IPV6 connection in Linux environment

Introduction: This article mainly introduces how ...

JavaScript implements double-ended queue

This article example shares the specific code of ...