Here is my image function if it helps:
Code: Select all
public function buildThumbnail($source,$thumb,$maxsize,$s = false,$exit = true){
#See if a valid image is being handled.
if($s === false) {
if (!$s = getimagesize($source)) exit("Could not get image's size.");
}
if(!$s) endpage("Invalid image file.",1);
#Check the thumbnails width and height
if ($s[0] <= $maxsize && $s[1] <= $maxsize) {
$w = $s[0];
$h = $s[1];
return true;
} else {
$xy = $maxsize;
$ss = min($xy/$s[0],$xy/$s[1]);
$w = (int)($s[0]*$ss);
$h = (int)($s[1]*$ss);
}
#Depending on the mime of the image, create a new one of that type.
switch ($s['mime']) {
case 'image/jpeg':$imagecreate='imagecreatefromjpeg';break;
case 'image/gif':$imagecreate='imagecreatefromgif';break;
case 'image/png':$imagecreate='imagecreatefrompng';break;
default:exit("The image must be jpeg,jpg,gif or png.");break;
}
$image = strval(str_replace('/',null,$s['mime']));
#Set aside some space for this image
if(!$r = imagecreatetruecolor($w,$h)) exit("Could not create a new image.");
$t = $imagecreate($source);
imagecopyresampled($r,$t,0,0,0,0,$w,$h,$s[0],$s[1]);
#Put some color in one of the pre allocated spaces
$border = ImageColorAllocate($r, 108, 108, 108);
#Save the image
$w = $w - 1;
$h = $h - 1;
$re = $image($r,$thumb,100);
#Clean up
imagedestroy($t);
imagedestroy($r);
@chmod($thumb,0777);
return $re;
}