View Full Version : Generating thumbnails in PHP

10-26-2007, 10:01 AM

I have a site where users have the option of uploading pictures when they make an entry. So I have a bunch of pictures in a sub-directory on the server.

Whenever someone looks at an entry, the script will generate a link that can be clicked, and that shows the picture in a separate pop-up window.

What I would like to do is to modify the script so that it will display a small thumbnail of the original picture on each entry.

Can you help me creating a php function that takes a picture from the server and displays a small thumbnail ?

Thanks in advance.

10-26-2007, 10:04 AM
There are two options here:
Display the image smaller, so that it is preloaded when you view the large image.
Or use php to render the image at a smaller size.

For the first, it's just an issue of math. Just change the width to a certain percent, etc.

For resizing with php:
Example 2 should be helpful.

10-26-2007, 05:31 PM
Use the GD library to resize the image. You will have to have the code on a seperate document and call this page just like you would an image.

<img src="image.php">