views:

55

answers:

1

I am using php and mysql. I allow my registered users to upload photos, the photos are store in filesystem format, then I will keep the original/max size of : width: 1600px and heigh: 1200px. In the user profile page, I would like to display the image, it maybe one of the 5 types of thumnails: 500x500, 300x300, 200x200, 100x100 or 50x50. What is the best way to create the thumbnails, here are my current solutions:

  1. I am thinking of create 1 thumbnail, then from that thumbnail, i will resize in [img src="" width="XX"] tag, alternatively, store the different thumbnails size in database, then get and display it

  2. Create 5 thumbnails for each photos? (I am afraid this is a bad way)

Whats the best practices?

+1  A: 

Don't use the width HTML attribute to resize, because that will waste both your and the client's bandwidth. You need to should serve all the images you use with the exact size desired. Where and whether you store the thumbnails depends on the on the usage pattern. A possible compromise would be to store them in memcached. Also, don't forget about HTTP caching.

Matthew Flaschen
meaning create 5 thumbnails for each uploaded image?
learner.php
Definitely serve the client the pre-scaled image. Don't have the browser do it. *When* you do the scaling depends on your app.
Matthew Flaschen
OK thanks. I think flickr is doing the same. http://www.flickr.com/help/photos/
learner.php
Browser resize will result in* jagged thumbnails.
Salman A
You do not have to create a different thumbnail for each size. IMHO what would be best in that case is to call a PHP script to serve up a resized image. This can be done on the fly, and you don't have to save it. Keep the original image and resize from there. That way you will always have the original to work with.
Joseph