Hey, the thumbnail gallery I use is pretty slow, because all thumbnails are generated on the fly.. Does anyone know of a faster method?
This is a call to show a photogallery on any given page:
$sgal is the name of the folder of pictures to show.
showgallery.php
This one loops through each file in the folder that is an image and gives the file name to thumb.php, which spits out a thumbnail.
thumb.php
This one uses GDI to output a thumbnail.
What can I do that would give me the least editing possible?
This is a call to show a photogallery on any given page:
<?php $sgal = "p_Sensi"; require_once("tn_gen/showgallery.php"); ?>
$sgal is the name of the folder of pictures to show.
showgallery.php
<?php $fCount = 0; if ($handle = opendir("bignails/$sgal")) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if (substr($file, strlen($file)-3, 3)=="jpg" || substr($file, strlen($file)-3, 3)=="JPG" ) { $fCount=$fCount+1; $fName[] = $file; } } } } closedir($handle); ?> <br/> <?php echo "Images in gallery: ",$fCount; ?> <table cellspacing = "2"> <?php $i = 0; while($i < $fCount){ ?> <tr> <td> <a href="bignails/<?php echo $sgal,"/",$fName[$i]; ?>"> <img src="tn_gen/thumb.php?<?php echo $sgal,"/",$fName[$i]; ?>"> </a> </td> <?php $i++; if ($i > $fCount-1){ break; } ?> <td> <a href="bignails/<?php echo $sgal,"/",$fName[$i]; ?>"> <img src="tn_gen/thumb.php?<?php echo $sgal,"/",$fName[$i]; ?>"> </a> </td> <?php $i++; if($i > $fCount-1){ break; } ?> <td> <a href="bignails/<?php echo $sgal,"/",$fName[$i]; ?>"> <img src="tn_gen/thumb.php?<?php echo $sgal,"/",$fName[$i]; ?>"> </a> </td> <?php $i++; if($i > $fCount-1){ break; } ?> <td> <a href="bignails/<?php echo $sgal,"/",$fName[$i]; ?>"> <img src="tn_gen/thumb.php?<?php echo $sgal,"/",$fName[$i]; ?>"> </a> </td> <?php $i++; if($i > $fCount-1){ break; } ?> <td> <a href="bignails/<?php echo $sgal,"/",$fName[$i]; ?>"> <img src="tn_gen/thumb.php?<?php echo $sgal,"/",$fName[$i]; ?>"> </a> </td> <?php $i++; if($i > $fCount-1){ break; } ?> <td> <a href="bignails/<?php echo $sgal,"/",$fName[$i]; ?>"> <img src="tn_gen/thumb.php?<?php echo $sgal,"/",$fName[$i]; ?>"> </a> </td> <?php $i++; if($i > $fCount-1){ break; } ?> </tr> <?php } ?> </table>
This one loops through each file in the folder that is an image and gives the file name to thumb.php, which spits out a thumbnail.
thumb.php
<?php header("Content-Type: image/jpeg"); $image_file = str_replace('..', '', $_SERVER['QUERY_STRING']); $image_path = "../bignails/$image_file"; function createthumb($src_image,$new_w,$new_h) { $src_img=imagecreatefromjpeg($src_image); $old_x=imageSX($src_img); $old_y=imageSY($src_img); if ($old_x > $old_y) { $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); } if ($old_x < $old_y) { $thumb_w=$old_x*($new_w/$old_y); $thumb_h=$new_h; } if ($old_x == $old_y) { $thumb_w=$new_w; $thumb_h=$new_h; } $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); imagejpeg($dst_img); imagedestroy($dst_img); imagedestroy($src_img); } createthumb($image_path,80,80); ?>
This one uses GDI to output a thumbnail.
What can I do that would give me the least editing possible?