
 Erik - 2007-03-10 03:41:16
I have add edit lite on it :
###############################################
 CLASS
###############################################
<?php
class thumbMaker {
	var $extension;
	var $upfile;
	var $dstfile;
	function makeThumb($max_width, $max_height, $upfile, $dstfile) {
		  
		$size = GetImageSize($upfile);
		 $width = $size[0];
		$height = $size[1];
		        
		$x_ratio = $max_width / $width;
		$y_ratio = $max_height / $height;
		if( ($width <= $max_width) && ($height <= $max_height) ) {
			$tn_width = $width;
			$tn_height = $height;
		
		} elseif (($x_ratio * $height) < $max_height) {
			$tn_height = ceil($x_ratio * $height);
			$tn_width = $max_width;
		} else {
		               $tn_width = ceil($y_ratio * $width);
		               $tn_height = $max_height;
		}
		if ($this->extension == "image/jpeg" || $this->extension == "image/jpg" || $this->extension == "image/pjpeg" ) {
			$src = ImageCreateFromJpeg($upfile);
			$dst = ImageCreateTrueColor($tn_width, $tn_height);
			ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
			ImageJpeg($dst, $dstfile);
			 } elseif( $this->extension == "image/gif" ) {
				$src = ImageCreateFromGif($upfile);
				$dst = ImageCreateTrueColor($tn_width, $tn_height);
				ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
				ImageGif($dst, $dstfile);
		
			 } elseif( $this->extension == "image/png" || $this->extension == "image/x-png" ) {
				$src = ImageCreateFromPNG($upfile);
				$dst = ImageCreateTrueColor($tn_width, $tn_height);
				ImageCopyResized($dst, $src, 0, 0, 0, 0, $tn_width, $tn_height, $width, $height);
				imagepng($dst, $dstfile);
			}
	}
}
?>
##########################################
  example.php
#########################################
<?php
// Simple thumbnail maker
// Variables available are
// extension, upfile, dstfile, max_width, max_height
// Currently supports GIF and JPG an PNG
// makeThumb($max_width, $max_height, $upfile, $dstfile);
$tum = new thumbMaker;
$tum->extension = $_FILES['userfile']['type'];
$tum->upfile = $_FILES['file']['tmp_name'];
$tum->dstfile = "mythumb/" . $_FILES['file']['name'];
$tum->makeThumb(100,100);
?>