I have been using a good PHP library, smart_resize_image, to resize images. Actually I use the library to resize any image before uploading it to S3 storage. It works very well.
Now my client wants to make any upcoming image as progressive image to make it load faster and reduce the image size. It can be done with imageinterlace function. Unfortunately, this function is not incorporated with the smart_resize_image function. But dont worry, the implementation is very simple. Just put a few code like this (the yellow shades) :
- function smart_resize_image($file,
- $width = 0,
- $height = 0,
- $proportional = false,
- $output = 'file',
- $delete_original = true,
- $use_linux_commands = false,
- $quality = 100)
- {
- ...
- imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $final_width, $final_height, $width_old, $height_old);
-
- if($info[2] == IMAGETYPE_JPEG){
- imageinterlace($image_resized,true);
- }
-
- # Taking care of original, if needed
- if ( $delete_original ) {
- if ( $use_linux_commands ) exec('rm '.$file);
- else @unlink($file);
- }
- ...
- }
Now, I can resize and interlace any image uploads. If you see the above code, the imageinterlace function only be applied for jpg image. This link explain that case. For the interlace image checking, please use this link : http://techslides.com/demos/progressive-test.html.