This article describes how to use progressive JPEG to improve user experience. For more information, see
This article describes how to use progressive JPEG to improve user experience. For more information, see
Today, we realized that there are two ways to save JPEG files: Baseline JPEG (standard) and Progressive JPEG (Progressive ). 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 size 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.
The advantage of progressive images is that users can see the outline of the final image without downloading the image, which can improve the user experience to a certain extent. (The standard type is recommended for waterfall websites)
In addition, the size of the progressive image is not much different from that of the basic image, and sometimes it may be smaller than the basic image. The disadvantage of progressive images is to eat the user's CPU and memory, but for the current computer, the calculation of this image is not much.
Now let's talk about how to save or convert an image to Progressive JPEG.
1. PhotoShop
In photoshop, there is "storage is the format used by the web". When it is turned on, "continuous" is the progressive JPEG.
For more information, see
2. Linux
Check whether it is progressive jpeg: identify-verbose filename.jpg | grep Interlace (if None is output, it is not progressive jpeg; If Plane is output, it is progressive jpeg .)
Convert basic jpeg to progressive jpeg:> convert infile.jpg-intermo-plane outfile.jpg
3. PHP
Using the imageinterlace and imagejpeg functions, we can easily solve the conversion problem.
<? Php
$ Im = imagecreatefrom#('pic.jpg ');
Imageinterlace ($ im, 1 );
Imagejpeg ($ im, './php_interlaced.jpg', 100 );
Imagedestroy ($ im );
?>
4. Python
Import PIL
From exceptions import IOError
Img = PIL. Image. open ("c: \ users \ biaodianfu \ pictures \ in.jpg ")
Destination = "c :\\ users \ biaodianfu \ pictures \ test.jpeg"
Try:
Img. save (destination, "JPEG", quality = 80, optimize = True, progressive = True)
Handle t IOError:
PIL. ImageFile. MAXBLOCK = img. size [0] * img. size [1]
Img. save (destination, "JPEG", quality = 80, optimize = True, progressive = True)
5. pivotran
Jpegtran-copy none-progressive
6. C #
Using (Image source = Image. FromFile (@ "D: \ temp \ test2.jpg ")){
ImageCodecInfo codec = ImageCodecInfo. GetImageEncoders (). First (c => c. MimeType = "image/jpeg ");
EncoderParameters parameters = new EncoderParameters (3 );
Parameters. Param [0] = new EncoderParameter (System. Drawing. Imaging. Encoder. Quality, 100L );
Parameters. Param [1] = new EncoderParameter (System. Drawing. Imaging. Encoder. ScanMethod, (int) EncoderValue. ScanMethodInterlaced );
Parameters. Param [2] = new EncoderParameter (System. Drawing. Imaging. Encoder. RenderMethod, (int) EncoderValue. RenderProgressive );
Source. Save (@ "D: \ temp \ saved.jpg", codec, parameters );
}
The above is all the content that uses progressive JPEG images to improve the page experience. It is very simple and practical. We recommend it to our friends here.