Zend - The PHP Company




Thumbnails

Add Code


Thumbs  

Type: application
Added by: wizbit
Entered: 16/04/2000
Last modified: 08/12/1999
Rating: - (fewer than 3 votes)
Views: 9146
Reads all GIF files from a directory and outputs thumbnails of them, generated on-the-fly to a user-specified size.


<?
     
// Thumbnail Generator
     // Wizbit Internet Services, 2000.
     
     // Feel free to use & modify this script as required.
     // Whilst we don't offer any official support for this
     // script, if you run into problems, send an email
     // to cgi@wizbit.net. From around June 2000, we will
     // also place all our free scripts on a website at
     // http://cgi.wizbit.net

     // Some variables - set these to the appropriate values. 
     // ** NO TRAILING SLASHES! ** 

     // $new_w is the thumbnail width, $new_h is the thumbnail height. 
    
    
$new_w=160;
    
$new_h=120;
    
     
// This should be a directory containing all the GIF files you  
     // want thumbnails for: 
    
$source"/www/htdocs/escape/scripts/images/test";

     
// Now the URL by which $source is referenced from a browser. 

    
$srcurl"/scripts/images/test";

     
// And this should be a publicly readable directory, writable  
     // by your web server daemon. 
    
$dest"/www/htdocs/escape/scripts/temp";

     
// Finally, this should be the URL (without the domain name)  
     // by which $dest is referenced from a web browser. 
    
$url"/scripts/temp";

     
// Nothing else should need changing, but feel free to experiment! 

    
$list= `ls -1 $source/*.gif`;
    
$files=split"n",$list);
    
$total=(count($files))-1;
    
$i=0;
    while (
$i<$total) {
        
$bits=split"/",$files[$i]);
        
$bitstot=count($bits);
        
$bitstot--;
        
$filename=$bits[$bitstot];
        
$src_img=ImageCreateFromGif"$files[$i]");
        
$dst_img=ImageCreate($new_w,$new_h);
        
ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
        
srand((double)microtime()*1000000);
        
$bob=rand(1,99999);
        
$size=GetImageSize"$files[$i]");
        
ImageGif($dst_img"$dest/thumb_$bob.gif");
    
     
// Put some code in here to display the image in a way appropriate 
     // for your site. The file example.php3 shows how to put the images 
     // in one row of a form, each one in a different cell. 

        
$i++;
    }
?>


Usage Example


<TABLE WIDTH="100%" CELLPADDING="2"  CELLSPACING="1">
<TR>
    <TD COLSPAN="30" CLASS=sectionhead ALIGN="center"><B>Thumbnails -
Click to enlarge</B></TD>
</TR>
<TR ALIGN="center">
<?
     
// Some variables - set these to the appropriate values. 
     // ** NO TRAILING SLASHES! ** 

     // $new_w is the thumbnail width, $new_h is the thumbnail height. 
    
    
$new_w=160;
    
$new_h=120;
    
     
// This should be a directory containing all the GIF files you  
     // want thumbnails for: 
    
$source"/www/htdocs/escape/scripts/images/test";

     
// Now the URL by which $source is referenced from a browser. 

    
$srcurl"/scripts/images/test";

     
// And this should be a publicly readable directory, writable  
     // by your web server daemon. 
    
$dest"/www/htdocs/escape/scripts/temp";

     
// Finally, this should be the URL (without the domain name)  
     // by which $dest is referenced from a web browser. 
    
$url"/scripts/temp";

     
// Nothing else should need changing, but feel free to experiment! 

    
$list= `ls -1 $source/*.gif`;
    
$files=split"n",$list);
    
$total=(count($files))-1;
    
$i=0;
    while (
$i<$total) {
        
$bits=split"/",$files[$i]);
        
$bitstot=count($bits);
        
$bitstot--;
        
$filename=$bits[$bitstot];
        
$src_img=ImageCreateFromGif"$files[$i]");
        
$dst_img=ImageCreate($new_w,$new_h);
        
ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
        
srand((double)microtime()*1000000);
        
$bob=rand(1,99999);
        
$size=GetImageSize"$files[$i]");
        
ImageGif($dst_img"$dest/thumb_$bob.gif");
?>
<TD><A TARGET="_new" HREF=" <? print  "$srcurl/$filename?>"><IMG BORDER="0" SRC=" <? print  "$url/thumb_$bob.gif"?>"></A></TD>
<?
        $i
++;
    }
?>
</TR>


Rate This Script





Search



This Category All Categories