-4

Google Page Speed Insights suggests me to optimize webpage images on a webpage I'm currently working on. Images are uploaded from a server. I want to display optimized images on the page but don't want the original image on the server to change. Is there any way to do this in PHP?

Shahzad
  • 11
  • 2

2 Answers2

0

You should reduce image size while uploading. Try this code.

reduce image size while uploading using the following PHP code used to upload image

Community
  • 1
  • 1
  • can i optimize image when page loads and show that image on the screen instead of image from server? – Shahzad Apr 27 '16 at 12:15
0

If you don't want the original image to change then you'll find any optimisations you perform to bring the file size down / serve a move appropriately sized image will be redundant due to the overhead of "optimising" the image on the fly. (Unless your original image is just that big)

As I see it, you have 3 options:

  1. Unless it has a massive impact (or you can envisage it will have a massive impact) just ignore Google Page Speeds for now.

  2. You can use lossless compression which will reduce the file size without reducing the quality of the image. This is something you can do on your server with various different apps (just google what type of server you have followed by lossless image compression)

  3. Just create a copy of the original image upon upload (or whenever) and serve that image to your users. The benefits to this are you can have different sized images which can be rendered for different devices, e.g. small image for mobile, and again you can use lossless compression on all of them. The downside to this is you'll obviously be using more server space.

Hope this helps!

Rwd
  • 34,180
  • 6
  • 64
  • 78