<?
	function make_thumbnail($image_path, $image_name, $thumb_path, $pixels, $protect=0) {
		
		// LOAD IMAGE
		$img = null;
		$ext = strtolower(end(explode('.', $image_path)));
		if ($ext == 'jpg' || $ext == 'jpeg') {
			$img = @imagecreatefromjpeg($image_path);
		} else if ($ext == 'png') {
			$img = @imagecreatefrompng($image_path);
		} else if ($ext == 'gif') {
			$img = @imagecreatefromgif($image_path);
		}
		
		// TEST THE IMAGE SIZE
		if ($img) {
		
			// GET THE IMAGE SIZE
			$width 	= imagesx($img);
			$height = imagesy($img);
			$scale 	= min(($pixels / $width), ($pixels / $height));
		
			// IF IMAGE IS TOO BIG
			if ($scale < 1) {
				$new_width 	= floor($scale * $width);
				$new_height = floor($scale * $height);
		
				// RESIZE IMAGE
				$tmp_img = imagecreatetruecolor($new_width, $new_height);
				imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
				imagedestroy($img);
				$img = $tmp_img;
				
				
				
				// INTERLACE THE IMAGE FOR PROGRESSIVE DOWNLOADING
				imageinterlace($img, 1);
			}
			
			// OVERLAY A COPYRIGHT LOGO OVER THE IMAGE
			if ($protect) {
				$img = copyright($img, '../../images/overlays/copyright.png');
			}
		}
		
		// CREATE THE NEW IMAGE
		if ($ext == 'jpg' || $ext == 'jpeg') {
			/*$spnMatrix = array(	array(-1,-1,-1), 
								array(-1,16,-1), 
								array(-1,-1,-1));
			$divisor = 8;
			$offset = 0; 
			imageconvolution($img, $spnMatrix, $divisor, $offset);*/
			$thumbnail_path = $thumb_path.$image_name.'.jpg';
			imagejpeg($img, $thumbnail_path, 90);
		} else if ($ext == 'png') {
			$thumbnail_path = $thumb_path.$image_name.'.png';
			imagepng($img, $thumbnail_path);
		} else if ($ext == 'gif') {
			$thumbnail_path = $thumb_path.$image_name.'.gif';
			imagegif($img, $thumbnail_path);
		}
	
	}
?>
