Best way to create thumbnails

Hi guys,

I’m creating an image gallery and one way or another I want to create the thumbnails dynamically. Originally I was going to have a script that physically creates a thumbnail image on image upload.

But now, I’m thinking it would much more flexible if I had a script that resized, cropped and displayed an thumbnail image on the fly, that way I can vary the sizes with less hassle.

Are there any implications doing it this way, I know there’s a million ways to skin a cat but is this a good way of doing it??

Any advice would be great

Thanks guys

Thanks for your replies guys.

On ‘the fly’ would refer to when images are displayed, obviously my script would check cache first.

I was going to create the images at a fix width after the image upload but if then 6 months down the line my client says can we have the thumbnails at 140x140 rather 90x90 it means I’m going to have to go through and resize all the original images, it would be even worse if there were two sizes of thumbnails we had to re-create?

Thanks for the link Rubble, I’ll check it out

ah ha of course forgot to inlcude that part

Depends at which point you reffer to when you say ‘on the fly’.

I’m in the middle of writing a gallery myself and I’m using SwfUpload which produces a new http request with each image upload in the upload queue. I’ve chosen to resize the image with each upload. My code generates a thumbnail of a standard size (90x90) on upload and simply leaves it at that.

Any other resizing could be done on an adhoc basis as this post suggests on stackoverflow :slight_smile:

You can resize dynamicaly using GD; Imagemagick and Imagick.

This also looks interesting:
Dynamic image resizing with PHP and mod-rewrite

It’s a good idea if you need the flexibility but make sure you cache the thumbnails.