<div class="codetitle"><a style="CURSOR: pointer" data="37139" class="copybut" id="copybut37139" onclick="doCopy('code37139')"> 代码如下:<div class="codebody" id="code37139"> function ImageResize($srcFile,$toW,$toH,$toFile="") { if($toFile==""){ $toFile = $srcFile; } $info = ""; $data = GetImageSize($srcFile,$info); switch ($data[2]) { case 1: if(!function_exists("imagecreatefromgif")){ echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!返回"; exit(); } $im = ImageCreateFromGIF($srcFile); break; case 2: if(!function_exists("imagecreatefromjpeg")){ echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!返回"; exit(); } $im = ImageCreateFromJpeg($srcFile); break; case 3: $im = ImageCreateFromPNG($srcFile); break; } $srcW=ImageSX($im); $srcH=ImageSY($im); $toWH=$toW/$toH; $srcWH=$srcW/$srcH; if($toWH<=$srcWH){ $ftoW=$toW; $ftoH=$ftoW($srcH/$srcW); } else{ $ftoH=$toH; $ftoW=$ftoH($srcW/$srcH); } if($srcW>$toW||$srcH>$toH) { if(function_exists("imagecreatetruecolor")){ @$ni = ImageCreateTrueColor($ftoW,$ftoH); if($ni) ImageCopyResampled($ni,$im,$ftoW,$ftoH,$srcW,$srcH); else{ $ni=ImageCreate($ftoW,$ftoH); ImageCopyResized($ni,$srcH); } }else{ $ni=ImageCreate($ftoW,$srcH); } if(function_exists('imagejpeg')) ImageJpeg($ni,$toFile); else ImagePNG($ni,$toFile); ImageDestroy($ni); } ImageDestroy($im); }
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|