You can use the EXIF thumbnail function to extract the thumnails for use in an image gallery. I've found this to be faster than using other GD functions to convert the image to a smaller one then save it.
Here is the code I use to generate thumbnails. Remember, this is more of a utility script, although its simple to modifiy it for use...
<?PHP
set_time_limit(0); //use this to make sure the script doesn't time out on large number of images.
//error_reporting(E_NONE); //use this to disable errors in a production script
function getmicrotime() {
$temparray=split(" ",microtime());
$returntime=$temparray[0]+$temparray[1];
return $returntime;
}
//lets make it slightly proper HTML. not valid, but can be changed quickly to be
echo "<html>
<head><title>Processing...</title></head>
<body>";
$maindir = "." ; //change this to what ever directory needs scanning
$mydir = opendir($maindir) ;
$starttime=getmicrotime();
$i = 0; //set the count of images processed to 0
while($fn = readdir($mydir)) //scan through the whole directory
{//open while
$startimagetime = getmicrotime();
$ext = strtolower(substr($fn,strlen($fn)-3)); //get the extension of an image
if ($ext == "jpg") {
$i++; //increase the number of images processed
echo $fn ." is being processed....<br>";
flush(); //needed to display each image progress
$image = exif_thumbnail($fn, $width, $height, $type);
if ($image!==false) {
//if there is a good enough thumbnail to use, we have it here.
//extract it and put it in the file, call it [original image name].thumb.jpg
$handle = fopen ($fn.".thumb.jpg", 'a');
//write the thumbnail image
fwrite($handle, $image);
} else {
// no thumbnail available, handle the error here
echo "No thumbnail available for file ".$fn."<br>";
}
}
}
closedir($mydir);
$endtime=getmicrotime();
echo "<br>All Images have been processed, script is finshed.<br>Total processing time: ";
print $endtime-$starttime;
echo "<br> Images processed: " .$i;
echo "</body>";
echo "</html>"
?>
Its a bit crude, I must admit, but it can easily be adapted to suit user.
NeoThermic