Performance or Hindrance - photo resizing

My question relates to images and resizing.

If you have a site (PHP) where visitors can upload photos which appear in a gallery. Would it be better to resize on upload to the different sizes or resize the photos on the fly? Either method would have there own impact of processing speed and disk space and I can imagine that there becomes a point that one method better suits higher volumes of users, while another saves on potential disk space upgrades…

Would be interesting to see what you all think.

Resize and cache (or save) the images as soon as possible. Never resize on the fly without saving the result.
Actually, I recommend to resize and save the images in the web root, let the server handle them from there not PHP.
What I mean by that, you’ll have the images delivered to the client the same way you deliver decorative images in HTML.

^^^^^ what he said.

I’d also vote for storing a reference copy in the database or somewhere else as a backup. But disk-caching the living daylights out of images makes sense these days.

To a large extent it depends on the number of images on the page.

Personally, I resize the images “on the fly”, either client side with javascript after preloading the images or by calling a php script in the <img>'s src attribute.

The downside to resizing the images on upload to thumbnail sizes is that if you want to change the thumbnail size in the future you will have to resize all the images again anyway. If you resize them on the fly, you only need to set the thumbnail size once in a script somewhere and that’s it.

Performance wise, resizing on the fly will take a bit longer but I have never found it to be a measureable extra length of time.

Thank you guys, that put to bed any questions I had on the issue. I haven’t given much thought to storing the original in the database, which would make adding additional deminsions at a later date much easier.


Max Height, that might work, for a small site with very very little traffic. But it is one that does not scale well.

It’s all relative I guess. Normally I’d have no more than 50-60 thumbnails on a page at the very most. What I normally would do is optimise the images for web publishing before uploading them. Before uploading, the images would be sized to the enlargement’s width and height and compressed to be typically somewhere between 20-90kB max. in size. I then preload the images while the page is loading and resize them on the fly to create the thumbnails and it all loads pretty quickly.

I suppose if you’re talking 100’s of images on a page or images that have not been optimised for web publishing, then maybe you would notice an increase in page performance if you had separate thumbnail and enlarged images. But I am very unlikely to ever need to have that many images on a page.

Now throw a couple hundred users trying to access the same data at the same time.