PHP converts a JPEG image to ProgressiveJPEG _ PHP Tutorial

Source: Internet
Author: User
PHP converts a JPEG image to ProgressiveJPEG. The JPEG file format can be saved in two ways. They are BaselineJPEG and ProgressiveJPEG. the two formats have the same size and image data, and their extensions are the same. The only difference is that JPEG file formats have two storage methods. 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.

The 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.

The code is as follows:


Identify-verbose outfile.jpg

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

Bytes. 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...

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.