Reputation: 4214
I am making a web application that needs to show 3 types of thumbnails to a user. No I might end up with a lot of thumbnail files on the server for a lot of users.
This makes me think is generating thumbnails on the fly is a better option than storing them?
Speed vs Storage vs Logic - Which one to go for?
Does anyone here ever faced such a dilemma - let me know!
I am using CodeIgniter and its inbuilt Image Library for generating thumbnails.
Upvotes: 3
Views: 575
Reputation: 522125
I would go with: generate when needed, store afterwards.
Link to the image using a URL like /img/42/400x300.jpg
. Through rewrite rules, you can fire up a PHP script should the image not exist. That script can then generate the requested image in the requested size and store it in the public web folder, where the web server can serve it directly the next time.
That gives you the best of both worlds: the image is not generated until needed, it is only generated once and it even makes it very flexible to work with different image sizes on the fly.
If you're worried about storage space, you can add a regular clean-up job which removes old images or perhaps analyses your access log files and removes images which where not accessed for some time.
Upvotes: 6
Reputation: 10469
My comment as an answer: (why not :)
My personal thoughts on this are, if you're anticipating a lot of users go with storage as the the load of creating dynamic thumbnails for every one of these users for every page load is going to hurt the server, maybe create it dynamically the first time it's ever viewed and then store it.
You may also take advantage of browser caching to save load and bandwidth. (marginal but every little helps)
Upvotes: 3