最模板 - 外贸网站建设,外贸网站模板

最模板

当前位置: 首页 > 建站教程 > CMS教程 > DedeCMS教程 >

织梦(dedecms)怎么样改变缩略图变形的问题

时间:2014-12-24 23:57来源: 作者: 点击:
打开/includes/image.func.php查找 function ImageResize($srcFile,$toW,$toH,$toFile=""),将下面一段

打开/includes/image.func.php查找 function ImageResize($srcFile,$toW,$toH,$toFile=""),将下面一段
function ImageResize($srcFile,$toW,$toH,$toFile="")
{
global $cfg_photo_type;
if($toFile=='') $toFile = $srcFile;
$info = '';
$srcInfo = GetImageSize($srcFile,$info);
switch ($srcInfo[2])
{
case 1:
if(!$cfg_photo_type['gif']) return false;
$im = imagecreatefromgif($srcFile);
break;
case 2:
if(!$cfg_photo_type['jpeg']) return false;
$im = imagecreatefromjpeg($srcFile);
break;
case 3:
if(!$cfg_photo_type['png']) return false;
$im = imagecreatefrompng($srcFile);
break;
case 6:
if(!$cfg_photo_type['bmp']) return false;
$im = imagecreatefromwbmp($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH=ImageSY($im);
if($srcW<=$toW && $srcH<=$toH ) return true;
$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);
}
switch ($srcInfo[2])
{
case 1:
imagegif($ni,$toFile)

break;
case 2:
imagejpeg($ni,$toFile,85);
break;
case 3:
imagepng($ni,$toFile);
break;
case 6:
imagebmp($ni,$toFile);
break;
default:
return false;
}
imagedestroy($ni);
}
imagedestroy($im);
return true;
}
替换成
function ImageResize($srcFile,$toW,$toH,$toFile="")
{
global $cfg_photo_type;
if($toFile=="")
{
$toFile = $srcFile;
}
$info = "";
$srcInfo = GetImageSize($srcFile,$info);
switch ($srcInfo[2])
{
case 1:
if(!$cfg_photo_type['gif'])
{
return false;
}
$im = imagecreatefromgif($srcFile);
break;
case 2:
if(!$cfg_photo_type['jpeg'])
{
return false;
}
$im = imagecreatefromjpeg($srcFile);
break;
case 3:
if(!$cfg_photo_type['png'])
{
return false;
}
$im = imagecreatefrompng($srcFile);
break;
case 6:
if(!$cfg_photo_type['bmp'])
{
return false;
}
$im = imagecreatefromwbmp($srcFile);
break;
}
$srcW=ImageSX($im);
$srcH=ImageSY($im);
if($srcW<=$toW && $srcH<=$toH )
{
return true;
}
//缩略生成并裁剪
$newW = $toH * $srcW / $srcH;
$newH = $toW * $srcH / $srcW;
if($newH >= $toH)
{
$ftoW = $toW;
$ftoH = $newH;
}
else
{
$ftoW = $newW;
$ftoH = $toH;
}
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);
}
//裁剪图片成标准缩略图
$new_imgx = imagecreatetruecolor($toW,$toH);
if($newH >= $toH)
{
imagecopyresampled($new_imgx,$ni,0,0,0,($newH - $toH)/2,$toW,$toH,$toW,$toH);
}
else
{
imagecopyresampled($new_imgx,$ni,0,0,($newW - $toW)/2,0,$toW,$toH,$toW,$toH);
}
switch ($srcInfo[2])
{
case 1:
imagegif($new_imgx,$toFile);
break;
case 2:
imagejpeg($new_imgx,$toFile,85);
break;
case 3:
imagepng($new_imgx,$toFile);
break;
case 6:
imagebmp($new_imgx,$toFile);
break;
default:
return false;
}
imagedestroy($new_imgx);
imagedestroy($ni);
}
imagedestroy($im);
return true;

 

(责任编辑:最模板)
------分隔线----------------------------
栏目列表
推荐内容