<BR>function ImageResize($srcFile,$toW,$toH,$toFile="") <BR>{ <BR>if($toFile==""){ $toFile = $srcFile; } <BR>$info = ""; <BR>$data = GetImageSize($srcFile,$info); <BR>switch ($data[2]) <BR>{ <BR>case 1: <BR>if(!function_exists("imagecreatefromgif")){ <BR>echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!返回"; <BR>exit(); <BR>} <BR>$im = ImageCreateFromGIF($srcFile); <BR>break; <BR>case 2: <BR>if(!function_exists("imagecreatefromjpeg")){ <BR>echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!返回"; <BR>exit(); <BR>} <BR>$im = ImageCreateFromJpeg($srcFile); <BR>break; <BR>case 3: <BR>$im = ImageCreateFromPNG($srcFile); <BR>break; <BR>} <BR>$srcW=ImageSX($im); <BR>$srcH=ImageSY($im); <BR>$toWH=$toW/$toH; <BR>$srcWH=$srcW/$srcH; <BR>if($toWH<=$srcWH){ <BR>$ftoW=$toW; <BR>$ftoH=$ftoW*($srcH/$srcW); <BR>} <BR>else{ <BR>$ftoH=$toH; <BR>$ftoW=$ftoH*($srcW/$srcH); <BR>} <BR>if($srcW>$toW||$srcH>$toH) <BR>{ <BR>if(function_exists("imagecreatetruecolor")){ <BR>@$ni = ImageCreateTrueC<strong style="color:transparent">¥本文来源gaodai#ma#com搞@@代~&码网^</strong><small>搞gaodaima代码</small>olor($ftoW,$ftoH); <BR>if($ni) ImageCopyResampled($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH); <BR>else{ <BR>$ni=ImageCreate($ftoW,$ftoH); <BR>ImageCopyResized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH); <BR>} <BR>}else{ <BR>$ni=ImageCreate($ftoW,$ftoH); <BR>ImageCopyResized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH); <BR>} <BR>if(function_exists('imagejpeg')) ImageJpeg($ni,$toFile); <BR>else ImagePNG($ni,$toFile); <BR>ImageDestroy($ni); <BR>} <BR>ImageDestroy($im); <BR>} <BR>