GROVER.
GROVER.

Reputation: 4378

converting image to all sizes on upload vs resizing on request via php

So I have a platform for users which allows them to upload a fair amount of pictures. At the moment, I have my server resizing and saving all images individually to my CDN (so I can pick the best option in order to reduce load time when a user requests to view it), but it seems very wasteful in regards to server storage.

The images are being converted into resolutions of 1200px, 500px, 140px, 40px and 24px.

What I'm wondering is, would it be more efficient to just save the file at 1200px, then serve it via PHP at the requested size using something like ImageMagick? Would there be any major trade-offs and if so, is it worth it?

What I'm doing right now:

https://v1x-3.hbcdn.net/user/filename-500x500.jpg

An example of what I could do:

https://v1x-3.hbcdn.net/image.php?type=user&file=filename&resolution=500

Cheers.

Upvotes: 2

Views: 187

Answers (1)

cetver
cetver

Reputation: 11829

No it's not, because:

  1. you have a small number of sizes

  2. if you will not use caching (image generation on first request only) you can DDOS yourself (image processing its a cpu affected process)

  3. have to do extra work if will use CDN like Cloudflare for HTTP-caching

It makes sense if you have a lot sizes of images, for example, API that supports multiple Andoid/IOS devices, meaning iphone 3 supports 320x320 image only and if you dont have users with such device, your server never creates such image.

Advice:

During image generation, use optimization it reduces image size with imperceptible loss of quality.

Upvotes: 3

Related Questions