Should I generate each thumbnail dynamically every time it is requested, or save them when loading an image?

Problem . I wanted to set up the image upload feature on my website. But I wanted to show both the original image and a small thumbnail.

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

How am I doing this now . Later, it seems to me better, because it will not take up much disk space, but it must again and again resize the image. Which one is better?

This is a common question for a web application, without a specific language.

Any idea how facebook or google do it?

Question . My question is how to create thumbnails and display them on a website, creating a copy of the original image with a smaller size or generating a thumbnail dynamically every time it is requested.

+5
source share
5 answers

Creating thumbnails at boot is almost always the best option. If the repository is troubling, you can convert them on demand and then cache the result in the repository. If its request is again before the cache expires, no conversion is required.

Storage is often quite cheap, so I probably would not go for this extra complexity.

+6

. . £ 70 .

+2

- , . . ;)

+1

CMS , .

, ", Google", CMS.

+1

"" .

- , - , 50 ,

( ), , . , , 50- ( ), .

, URL-, <img src="images/thumbnail/foobar.jpg"> , - , <img src="thumbnail.php?image=image/foobar.jpg>, querystrings ,

-, ; ImageMagick . , , , , , , , .

The question also arises of keeping thumbnails in sync with the originals - if the user uploads a new image, you must make sure to update the thumbnail; if the original is deleted, you must also delete the thumbnail.

+1
source

All Articles