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

Blog    

Recommend

MySQL 8.0.20 installation and configuration method graphic tutorial

MySQL download and installation (version 8.0.20) ...

Basic knowledge of MySQL database

Table of contents 1. Understanding Databases 1.1 ...

Play mp3 or flash player code on the web page

Copy code The code is as follows: <object id=&...

The best solution for resetting the root password of MySQL 8.0.23

This method was edited on February 7, 2021. The v...

Native js implements shopping cart logic and functions

This article example shares the specific code of ...

Summary of the use of special operators in MySql

Preface There are 4 types of operators in MySQL, ...

JavaScript determines whether the browser is IE

As a front-end developer, I can’t avoid IE’s pitf...

Solution to the problem of slow docker pull image speed

Currently, Docker has an official mirror for Chin...

Docker uses dockerfile to start node.js application

Writing a Dockerfile Taking the directory automat...

A detailed introduction to HTML page loading and parsing process

The order in which the browser loads and renders H...

MySQL 8.0.17 installation graphic tutorial

This article shares with you the MySQL 8.0.17 ins...

One line of code teaches you how to hide Linux processes

Friends always ask me how to hide Linux processes...

jQuery plugin to achieve carousel effect

A jQuery plugin every day - jQuery plugin to impl...

Is your website suitable for IE8?

During the Olympic Games, IE 8 Beta 2 will be rele...