#native_company# #native_desc#
#native_cta#

Thumbnail Function

By Lee Willmann
on October 7, 2006

Version: 1.01

Type: Function

Category: Graphics

License: GNU General Public License

Description: A simple function that takes a png image and creates a thumbnail in a subdirectory.

function make_thumb($imagefile, $new_w=150, $new_h=100) 
{ 
	// get source image info.
	$img_data=getimagesize($imagefile); 
	$src_w=$img_data[0]; 
	$src_h=$img_data[1]; 

	// get source image
	$src_img=imagecreatefromjpeg($imagefile) or die ("Cannot open source"); 

	// create a target image
	$dst_img=imagecreatetruecolor($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("thumbs");

	// if the image already exists blow it away.
	if ( file_exists($imagefile) ) 
	{ 
	unlink($imagefile); 
	} 

	// I use thumb_ to show that it is a thumbnail. 
	// save the new image as a png.
	imagejpeg($dst_img,$imagefile); 

	// free up the memory.
	ImageDestroy($src_img); 
	ImageDestroy($dst_img); 

}