function resizeimage($image,$width,$height,$scale) {
list($imagewidth, $imageheight, $imagetype) = getimagesize($image);
$imagetype = image_type_to_mime_type($imagetype);
$newimagewidth = ceil($width * $scale);
$newimageheight = ceil($height * $scale);
$newimage = imagecreatetruecolor($newimagewidth,$newimageheight);
switch($imagetype) {
case "image/gif":
$source=imagecreatefromgif($image);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
$source=imagecreatefromjpeg($image);
break;
case "image/png":
case "image/x-png":
$source=imagecreatefrompng($image);
break;
}
imagecopyresampled($newimage,$source,0,0,0,0,$newimagewidth,$newimageheight,$width,$height);
switch($imagetype) {
case "image/gif":
imagegif($newimage,$image);
break;
case "image/pjpeg":
case "image/jpeg":
case "image/jpg":
imagejpeg($newimage,$image,90);
break;
case "image/png":
case "image/x-png":
imagepng($newimage,$image);
break;
}
chmod($image, 0777);
return $image;
}
?>
|