Resize and Interlace Image

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) :

  1. function smart_resize_image($file,
  2. $width = 0,
  3. $height = 0,
  4. $proportional = false,
  5. $output = 'file',
  6. $delete_original = true,
  7. $use_linux_commands = false,
  8. $quality = 100)
  9. {
  10. ...
  11. imagecopyresampled($image_resized, $image, 0, 0, 0, 0, $final_width, $final_height, $width_old, $height_old);
  12.  
  13. if($info[2] == IMAGETYPE_JPEG){
  14. imageinterlace($image_resized,true);
  15. }
  16.  
  17. # Taking care of original, if needed
  18. if ( $delete_original ) {
  19. if ( $use_linux_commands ) exec('rm '.$file);
  20. else @unlink($file);
  21. }
  22. ...
  23. }

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.

Loading