织梦图集 上传图片小于设定尺寸 缩略图生成失败的解决办法

时间:2018-12-10
织梦图集中,上传的图片像素宽高小于系统设置定的这个尺寸: 
较小的这些图片就会无法生成缩略图,导致图集在网页上缩略图显示X叉号,这应该是织梦DEDEcms的一个历史遗漏bug,可用下面方法修复。
/include/helpers/,这个文件中搜索,下面的代码:

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);
        }
 
然后用下面的大片代码替换:
 
$ftoW=$toH; 
[size=; font-size: inherit,inherit]                $ftoH=$toH; 
        ///
[size=; font-size: inherit,inherit]        if( $srcH<=$toH &&  $srcW<=$toW ) 
[size=; font-size: inherit,inherit]            { 
[size=; font-size: inherit,inherit]                $ftoW=$srcW; 
[size=; font-size: inherit,inherit]                $ftoH=$srcH; 
[size=; font-size: inherit,inherit]                if(function_exists("imagecreatetruecolor")) 
[size=; font-size: inherit,inherit]                { 
[size=; font-size: inherit,inherit]                    @$ni = imagecreatetruecolor($ftoW,$ftoH); 
[size=; font-size: inherit,inherit]                    if($ni) 
[size=; font-size: inherit,inherit]                    { 
[size=; font-size: inherit,inherit]                    imagecopyresampled($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH); 
[size=; font-size: inherit,inherit]                    } 
[size=; font-size: inherit,inherit]                    else 
[size=; font-size: inherit,inherit]                    { 
[size=; font-size: inherit,inherit]                    $ni=imagecreate($ftoW,$ftoH); 
[size=; font-size: inherit,inherit]                    imagecopyresized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH); 
[size=; font-size: inherit,inherit]                    } 
[size=; font-size: inherit,inherit]                    } 
[size=; font-size: inherit,inherit]                else 
[size=; font-size: inherit,inherit]                { 
[size=; font-size: inherit,inherit]                    $ni=imagecreate($ftoW,$ftoH); 
[size=; font-size: inherit,inherit]                    imagecopyresized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH); 
[size=; font-size: inherit,inherit]                } 
[size=; font-size: inherit,inherit]                switch ($srcInfo[2]) 
[size=; font-size: inherit,inherit]                { 
[size=; font-size: inherit,inherit]                    case 1: 
[size=; font-size: inherit,inherit]                    imagegif($ni,$toFile); 
[size=; font-size: inherit,inherit]                    break; 
[size=; font-size: inherit,inherit]                    case 2: 
[size=; font-size: inherit,inherit]                    imagejpeg($ni,$toFile,100); 
[size=; font-size: inherit,inherit]                    break; 
[size=; font-size: inherit,inherit]                    case 3: 
[size=; font-size: inherit,inherit]                    imagepng($ni,$toFile); 
[size=; font-size: inherit,inherit]                    break; 
[size=; font-size: inherit,inherit]                    case 6: 
[size=; font-size: inherit,inherit]                    imagebmp($ni,$toFile); 
[size=; font-size: inherit,inherit]                    break; 
[size=; font-size: inherit,inherit]                    default: 
[size=; font-size: inherit,inherit]                    return false; 
[size=; font-size: inherit,inherit]                } 
[size=; font-size: inherit,inherit]                imagedestroy($ni); 
[size=; font-size: inherit,inherit]            } ///

        $toWH=$toW/$toH;
        $srcWH=$srcW/$srcH;
        if($toWH<=$srcWH)
        {
            $ftoW=$toW;
            $ftoH=$ftoW*($srcH/$srcW);
        }
        else
        {
            $ftoH=$toH;
            $ftoW=$ftoH*($srcW/$srcH);
        }
 
这样织梦上传的图,就不会显示x号了。
上一条:如何在织梦DEDECMS网站栏目中增加统计文章数量的方法 下一条:dede:list和dede:arclist列表按权重排序修改方法

相关文章

最新文章