Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I generate each thumbnail dynamically every time it is requested, or store them on image upload? [duplicate]

Problem - I wanted to set up an image-uploading feature in my website. But I wanted to show both- the original image and a small thumbnail of the image.

Choices - Which way is better - to create a separate image (thumbnail) in a directory when the image is uploaded or to show a smaller version by reducing its height and width in the fixed ratio every time the image is requested?

How I am doing it currently - The later one sounds better to me because it won't be taking much size on the disk but it has to resize the image again and again. Which one do you think is better?

This is a general question for web application, no language in specific.

Any idea how facebook or google do it?

Question - My question is how to generate thumbnails and show them on a website - by creating a copy of the original image with smaller dimension or by generating the thumbnail dynamically every time it is requested.

like image 965
ShuklaSannidhya Avatar asked Feb 07 '13 15:02

ShuklaSannidhya


3 Answers

Creating the thumbnail on upload is almost always the better option. If storage is a concern you could convert them on the request and then cache the result in a memory store. If its requested again before the cache expires, no conversion will be needed.

Storage is often pretty cheap, so I would probably not go for that extra complexity.

like image 146
datasage Avatar answered Oct 02 '22 14:10

datasage


Just create a thumbnail version and save to disk. Hard disk space is very cheap. £70 for a couple of TB.

like image 30
Ed Heal Avatar answered Oct 02 '22 14:10

Ed Heal


Creating a thumbnail is a better option and it doesn't cost much disk space. Your client will also load smaller size when opening your pages. converting the image upon request will cost event more time to load your page ;)

like image 21
Hendyanto Avatar answered Oct 02 '22 13:10

Hendyanto