This script will generate a thumbnail image of any JPEG image that is sent to it...
This file is independant, and mine is named resize.php you can send an image to the php file, and then return the thumbnail for viewing. It does require some work, but WELL worth the effort once you've mastered the script an example of this script can be seen here http://www.passionstandardpoodles.com/photos/
In this example, the resize is transparent to the user, because the script on the display page resizes the image if it isn't there, and then displays the saved image, and not the resized one. otherwise, on a right click and properties on a generated image, the image name would be
whateverdomain.com/php_scripts/resize.php?main_file=myphoto.jpg
NOTE: This script requires the GD image library to be compiled, and to my knowledge only works on a *nix server. PHP must also be installed using GD support.
The following elements are required for compiling PHP with GD support: (PHP 4.2.2 was current release last time I used this)
--with-gd=/your/path \
--with-jpeg-dir=/your/path \
--with-png-dir=/your/path \
--with-freetype-dir=/your/path \
--with-zlib-dir=/your/path
$image = "$path_to_images";
$savelocation = "$path_to_thumbnail_dir";
if(!file_exists("$path_to_images"))
{
$oldumask = umask(0);
mkdir("$path_to_thumbnail_dir", 0777);
umask($oldumask);
}
if (!$max_width)
$max_width = 125;
if (!$max_height)
$max_height = 125;
$size = GetImageSize($image);
$width = $size[0];
$height = $size[1];
$x_ratio = $max_width / $width;
$y_ratio = $max_height / $height;
if ( ($width <= $max_width) && ($height <= $max_height) ) {
$tn_width = $width;
$tn_height = $height;
}
else if (($x_ratio * $height) < $max_height) {
$tn_height = ceil($x_ratio * $height);
$tn_width = $max_width;
}
else {
$tn_width = ceil($y_ratio * $width);
$tn_height = $max_height;
}
$src = ImageCreateFromJpeg($image);
$dst = ImageCreate($tn_width,$tn_height);
ImageCopyResized($dst, $src, 0, 0, 0, 0,
$tn_width,$tn_height,$width,$height);
ImageJpeg($dst,"$savelocation"."thumb_$file");
ImageDestroy($src);
ImageDestroy($dst);
NOTE: To save a few hours of headache, there MUST NOT be ANY whitespace in this file before the variables are reached. so, do not put any empty lines at the start of the file!
I will be creating a tutorial on this soon, but this should be enough to get you going. There is a lot to making the GD work properly, and I really only recommend using it if you are setting up a large image gallery, and don't want to spend hours creating thumbnails and having to upload them all. :)