欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

兼容性最強(qiáng)的PHP生成縮略圖的函數(shù)代碼(修改版)

 更新時(shí)間:2011年01月18日 00:00:25   作者:  
寫(xiě)通用性程序考慮兼容性是很頭痛的事情,關(guān)于用PHP生成縮略圖的代碼很多,不過(guò)能完全兼容gd1.6和gd2.x,并能保證縮圖清晰性的代碼幾乎沒(méi)有,我把我以前的代碼改了一下,就能實(shí)現(xiàn)了。
復(fù)制代碼 代碼如下:

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庫(kù)不能使用GIF格式的圖片,請(qǐng)使用Jpeg或PNG格式!<a href='javascript:go(-1);'>返回</a>";
exit();
}
$im = ImageCreateFromGIF($srcFile);
break;
case 2:
if(!function_exists("imagecreatefromjpeg")){
echo "你的GD庫(kù)不能使用jpeg格式的圖片,請(qǐng)使用其它格式的圖片!<a href='javascript:go(-1);'>返回</a>";
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,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);
else{
$ni=ImageCreate($ftoW,$ftoH);
ImageCopyResized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);
}
}else{
$ni=ImageCreate($ftoW,$ftoH);
ImageCopyResized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH);
}
if(function_exists('imagejpeg')) ImageJpeg($ni,$toFile);
else ImagePNG($ni,$toFile);
ImageDestroy($ni);
}
ImageDestroy($im);
}

相關(guān)文章

最新評(píng)論