function image_create_thumb
($filename,
$width,
$height)
{
list($image["Width"],
$image["Height"],
$image["Type"]) =
getimagesize($filename);
if($image["Type"] == IMG_JPG ||
$image["Type"] == IMG_JPEG
)
{
$im_image = ImageCreateFromJPEG
($filename);
}
if($image["Type"] == IMG_GIF
)
{
$im_image = ImageCreateFromGIF
($filename);
}
if($image["Type"] == IMG_PNG
)
{
$im_image = ImageCreateFromPNG
($filename);
}
if($image["Width"] >
$image["Height"])
{
$scale =
$width /
$image["Width"];
$thumb_width =
$width;
$thumb_height =
floor($image["Height"]*
$scale);
}
else
{
$scale =
$height /
$image["Height"];
$thumb_height =
$height;
$thumb_width =
floor($image["Width"]*
$scale);
}
$im_thumb = @ImageCreateTrueColor
($thumb_width,
$thumb_height) or
die("Cannot Initialize new GD image stream");
ImageCopyResized
($im_thumb,
$im_image,
0,
0,
0,
0,
$thumb_width,
$thumb_height,
$image["Width"],
$image["Height"]);
ImageDestroy
($im_image);
ImagePNG
($im_thumb,
$filename);
ImageDestroy
($im_thumb);
return true;
}//image_create_thumb($filename, $width, $height)