writethumb.php to HTML

index

USE AT OWN RISK

Generated: Tue Jul 31 15:22:18 2007 from writethumb.php 2005/10/31 2.1 KB bytes.


<?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
$maindir = "images/page00" ; //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
   $fnm = substr($fn,0,strlen($fn)-4);
   $fpath = $maindir . "/" . $fn;
 echo $fpath ." is being processed....<br>";
 flush(); //needed to display each image progress
 $image = exif_thumbnail($fpath, $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');
 $handle = fopen ($fnm."-t.jpg", 'w');
 //write the thumbnail image
 fwrite($handle, $image);
   fclose($handle);
 } 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>"

?>

index

Valid HTML 4.01 Transitional