rendered paste bodymakeThumb.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 == "jpg"){
$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);
} else {
$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);
}
}
}
?>
example.php
<?
// Simple thumbnail maker
// Variables available are
// extension, upfile, dstfile, max_width, max_height
// Currently supports GIF and JPG
// makeThumb($max_width, $max_height, $upfile, $dstfile);
include('makeThumb.class.php');
$tum = new thumbMaker;
$grabExt = explode(".", $_FILES['file']['name']);
$tum->extension = $grabExt[1];
$tum->upfile = $_FILES['file']['tmp_name'];
$tum->dstfile = "mythumb/" . $_FILES['file']['name'];
$tum->makeThumb(100,100);
?>