Automatically Creating a Thumbnail With PHP
I’ve had several occasions to work on web sites for photographers. One of the most important features on a photographer’s site is the galleries of photos. Potential customers want to see the quality of work. Unfortunately updating the site with the latest and greatest shots from their portfolio can be a time consuming process for photographers. There’s a certain amount of prep work required, part of which is creating a thumbnail version of each photo. Since computers are great for automating repetitive tasks, I cobbled together a few pieces of code I found on the web into a PHP snippet that will create a thumbnail from an existing image.
The code below creates a thumbnail that is 100 pixels wide. With a few changes to the middle three lines of code you could easily create thumbnails with a set height or even a set percentage size of the original image.
$starting_image = imagecreatefromjpeg(”folder/image.jpg”);
$width = imagesx($starting_image);
$height = imagesy($starting_image);$thumb_width = 100;
$constant = $width/$thumb_width;
$thumb_height = round($height/$constant, 0);$thumb_image = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($thumb_image, $starting_image, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height);
imagejpeg($thumb_image, “folder/thumb.jpg”);
If you’re working with an older version of PHP, some of these functions may not be defined. Upgrading your version of PHP is probably the easiest solution, but if that isn’t an option you can just set up the GD library of functions.

This code is not working…
can any one help me?
it says…
“Call to undefined function imagecreatefromjpeg()”
Shaaa: the most likely explanation is that you are using a version of PHP that does not include the GD library automatically bundled. (I believe they started bundling it with the core PHP code in version 4.3.) You can either upgrade your version of PHP or manually set up the GD library. You can download the files and find instructions at:
http://www.libgd.org/Main_Page