Search:

Categories



Thumbnail function

<?php 
 
 
function make_thumb($imagefile, $new_w=75, $new_h=75) 
{ 
// get source image info.
$img_data=getimagesize($imagefile); 
$src_w=$img_data[0]; 
$src_h=$img_data[1]; 
 
// get source image
$src_img=ImageCreateFromPNG($imagefile) or die ("Cannot open source"); 
 
// create a target image
$dst_img=imagecreate($new_w,$new_h); 
 
// create the thumbnail
imagecopyresized($dst_img,$src_img, 0, 0, 0, 0, $new_w, $new_h, $src_w, $src 
_h); 
 
// switch to subdir.
chdir("thumbnails");
 
// if the image already exists blow it away.
if ( file_exists("thumb_".$imagefile) ) 
{ 
unlink("thumb_".$imagefile); 
} 
 
// I use thumb_ to show that it is a thumbnail. 
// save the new image as a png.
imagepng($dst_img,"thumb_".$imagefile); 
 
// free up the memory.
ImageDestroy($src_img); 
ImageDestroy($dst_img); 
 
} 
 
// demo of use.
make_thumb("image1.png"); 
 
make_thumb("image1.png", 200, 200);
 
?>
Share

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  

  

  


*