PHP converts a JPEG image to Progressive JPEG

Source: Internet
Author: User

The JPEG file format can be saved in two ways. 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 is that they are displayed differently.

Baseline JPEG

This type of JPEG file is stored in the JPEG file by scanning from top to bottom. When you open this file to display its content, the data will be displayed from top to bottom lines in the storage order until all the data is read, the entire image is displayed. If the file is large or the network download speed is slow, the image is loaded by one row. This format of JPEG has no advantages. Therefore, Progressive JPEG is generally recommended.

Progressive JPEG

Unlike Baseline, the Progressive JPEG file contains multiple scans. These scans are stored in JPEG files. When opening a file, the blurred outline of the entire image is displayed first. As the number of scans increases, the image becomes clearer and clearer. The main advantage of this format is that when the network is slow, you can see the picture outline to know what the picture is being loaded. When some websites open large images, you will notice this technology.


If your network speed is the same as that of snails, you can see the effect. In fact, you will often see this effect on large websites such as qzone and Weibo.

PHP code can also be converted to Progressive jpg.

Copy codeThe Code is as follows:
<? Php
 
$ Im = imagecreatefrom#('file.jpg ');
// Sets the line-through-line scan to set the line-through-line scan bit mark. If the image is in JPEG format, the image is created as progressive JPEG. Php Manual
Imageinterlace ($ im, 1 );
Imagejpeg ($ im, './outfile.jpg', 80 );
Imagedestroy ($ im );
 
?>

How can I see whether the image is in the Progressive or Baseline format?

I currently know that I use the identity command in the ImageMagick software to view image resources.
Copy codeThe Code is as follows:
Identify-verbose outfile.jpg

If you see an image with the attribute "Interlace: JPEG", it is a sive ssive image.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.