Upload images using PHP?

0

I have a page that loads about 90% of the content based on images, the size of the images varies from 20kb up to 150kb depending on the size of the image, to improve page load performance I am thinking of calling the images through a php script that will identify if the user is using Chrome or another browser with WebP support, and then load the image with the extension most appropriate for the browser. My question is:

  • Is it good to make this call through a php script?
asked by anonymous 09.12.2016 / 12:19

1 answer

3

In my opinion, it is not good to use PHP to upload images.

If you do, you will be causing PHP to process all the content of an image and then send a response to the browser.

This can be expensive for the server in terms of processing, since PHP needs to use memory to render that image.

Not to mention that the browser has a specific mechanism for image caches. Maybe by PHP, you can not enjoy this functionality, since it is actually a PHP script that will be processed, not an image.

The solution I usually use for cases where I need to use PHP to render images is: Process the image once, giving it the desired format, and save it. I usually convert them all to the same format.

I believe that if you want to improve the performance of your images, you can invest some time in creating a system of thumbs. Using resized images or with appropriate treatment, you can achieve a desired performance. But I do not think loading always with a PHP script is appropriate. Now, if you do this once, creating an image optimizes static, I think it would be a good solution.

    
09.12.2016 / 12:21