Method of converting JPEG picture into Progressive JPEG by PHP

  • 2021-07-06 10:33:29
  • OfStack

There are two ways to save the JPEG file format. They are Baseline JPEG and Progressive JPEG.

The two formats have the same size and image data, and their extensions are the same. The only difference between 1 and 1 is that they are displayed in different ways.

Baseline JPEG

This type of JPEG file is stored by scanning from top to bottom, and every 1 line is stored in JPEG file in sequence. When you open this file to display its contents, the data will be displayed one line at a time from top to bottom in the order in which it was stored, until all the data has been read, and the whole picture is displayed. If the file is large or the network download speed is slow, you will see the effect that the picture is loaded by 1 line. JPEG in this format has no advantages, so Progressive JPEG is generally recommended for 1

Progressive JPEG

Unlike the Baseline1 pass scan, the Progressive JPEG file contains multiple scans, which are stored sequentially in the JPEG file. In the process of opening the file, the blurred outline of the whole picture will be displayed first, and the picture will become clearer and clearer with the increase of scanning times. The main advantage of this format is that when the network is slow, you can see the outline of the picture and know what the picture is loading. You will notice this technology when you open larger pictures on 1 website.


If your network speed and snail 1, you should be able to see the effect, in fact, you in qzone, Weibo and other large websites you will often see such an effect.

The PHP code can also convert it to the jpg of the Progressive.


<?php
 
$im = imagecreatefromjpeg('file.jpg');
// Set interlacing The interlaced bit flag is set and the image is used JPEG Format, the image is created as progressive JPEG . php Manual
imageinterlace($im, 1);
imagejpeg($im, './outfile.jpg', 80);
imagedestroy($im);
 
?>

How do I see whether the picture is in Progressive or Baseline format?

What I know now is to use the identity command with ImageMagick software to view image resources


identify -verbose outfile.jpg

If you see an Interlace attribute: JPEG is an Progressive image.


Related articles: