在使用Dedecms CMS时,如果上传的图片像素宽高小于系统设定的尺寸,这些较小的图片将无法生成缩略图。这会导致图集在网页上显示为X叉号,这是Dedecms CMS的一个历史遗留问题。以下是如何修复这一问题的详细步骤。 首先,进入/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;
$ftoH=$toH;

if( $srcH<=$toH &&  $srcW<=$toW )
{
    $ftoW=$srcW;
    $ftoH=$srcH;
    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,100);
            break;
        case 3:
            imagepng($ni,$toFile);
            break;
        case 6:
            imagebmp($ni,$toFile);
            break;
        default:
            return false;
    }
    imagedestroy($ni);
}

$toWH=$toW/$toH;
$srcWH=$srcW/$srcH;
if($toWH<=$srcWH)
{
    $ftoW=$toW;
    $ftoH=$ftoW*($srcH/$srcW);
}
else
{
    $ftoH=$toH;
    $ftoW=$ftoH*($srcW/$srcH);
}
    
完成以上步骤后,Dedecms CMS上传的图片就不会再显示X号了。通过这种方法,可以确保所有上传的图片都能正确生成缩略图,从而提升用户体验和网站的专业度。注意在修改前备份原始文件,以便在需要时恢复。这样不仅解决了问题,还保证了系统的稳定性。希望这篇指南对您有所帮助!