function ResizeImg($image, $new_width, $new_height)
{
eregi(".(.*)$",$image,$regs);
switch($regs[1])
{
case "gif": $srcImage = ImageCreateFromGIF($image);
break;
case "jpg": $srcImage = ImageCreateFromJPEG($image);
break;
case "png": $srcImage = ImageCreateFromPNG($image);
break;
default : $srcImage = ImageCreateFromJPEG($image);
break;
}
$srcWidth = ImageSX($srcImage);
$srcHeight = ImageSY($srcImage);
$ratioWidth = $srcWidth/$new_width;
$ratioHeight = $srcHeight/$new_height;
if( $ratioWidth < $ratioHeight)
{
$destWidth = $srcWidth/$ratioHeight;
$destHeight = $new_height;
}
else
{
$destWidth = $new_width;
$destHeight = $srcHeight/$ratioWidth;
}
$destImage = imagecreate($destWidth, $destHeight);
ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight);
header ("Content-type: image/jpeg");
ImageJPEG($destImage,"",100);
ImageDestroy($srcImage);
ImageDestroy($destImage);
}