PHP to convert JPEG images to progressive JPEG _php instance

Source: Internet
Author: User

There are two ways to save a JPEG file format. They are baseline JPEG and progressive JPEG.

Both formats have the same size and image data, and their extensions are the same, and the only difference is that they are displayed in a different way.

Baseline JPEG

This type of JPEG file is stored in a JPEG file in the order of each row, by scanning from top to bottom. When this file is opened to display its contents, the data is displayed from the top to the next line in the order in which it was stored, until all the data has been read and the entire picture is displayed. If the file is large or the network download speed is slow, then you will see the image is loaded with a row of rows, this format JPEG does not have any advantages, therefore, generally recommended to use progressive JPEG

Progressive JPEG

Unlike the baseline scan, the progressive JPEG file contains multiple scans, which are stored in a JPEG file. When you open a file, you will first show the blur outline of the entire picture, and as the number of scans increases, the picture becomes more and more clear. The main advantage of this format is that when the network is slow, you can see the outline of the picture to know what the picture is loading. You'll notice this technique when you open a larger picture on some Web sites.


If your speed and the same as the snail, you should be able to see the effect, in fact, you in Qzone, Weibo and other large sites you will often see this effect.

The PHP code can also convert it into a progressive jpg.

Copy Code code as follows:

<?php

$im = Imagecreatefromjpeg (' file.jpg ');
Set interlaced scanning to set the interleaved bit tag while the image uses the JPEG format, the image is created as progressive JPEG. PHP Manual
Imageinterlace ($im, 1);
Imagejpeg ($im, './outfile.jpg ', 80);
Imagedestroy ($im);

?>

How do I think the picture is progressive or baseline format?

I currently know that it is using the ImageMagick software with the identity command to view the image resources

Copy Code code as follows:

Identify-verbose outfile.jpg

If you see an attribute of Interlace:jpeg it is a progressive picture.

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.