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

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!
织梦图集中,上传的图片像素宽高小于系统设置定的这个尺寸: 
较小的这些图片就会无法生成缩略图,导致图集在网页上缩略图显示X叉号,这应该是织梦DEDEcms的一个历史遗漏bug,可用下面方法修复。
/include/helpers/,这个文件中搜索,下面的代码
  1. if($srcW<=$toW && $srcH<=$toH ) return TRUE; 
  2.         $toWH=$toW/$toH; 
  3.         $srcWH=$srcW/$srcH; 
  4.         if($toWH<=$srcWH) 
  5.        { 
  6.             $ftoW=$toW; 
  7.             $ftoH=$ftoW*($srcH/$srcW); 
  8.         } 
  9.         else 
  10.         { 
  11.             $ftoH=$toH; 
  12.             $ftoW=$ftoH*($srcW/$srcH); 
  13.         } 
 
然后用下面的大片代码替换:
  1. $ftoW=$toH; 
  2. [size=; font-size: inherit,inherit]                $ftoH=$toH; 
  3.         /// 
  4. [size=; font-size: inherit,inherit]        if( $srcH<=$toH &&  $srcW<=$toW ) 
  5. [size=; font-size: inherit,inherit]            { 
  6. [size=; font-size: inherit,inherit]                $ftoW=$srcW; 
  7. [size=; font-size: inherit,inherit]                $ftoH=$srcH; 
  8. [size=; font-size: inherit,inherit]                if(function_exists("imagecreatetruecolor")) 
  9. [size=; font-size: inherit,inherit]                { 
  10. [size=; font-size: inherit,inherit]                    @$ni = imagecreatetruecolor($ftoW,$ftoH); 
  11. [size=; font-size: inherit,inherit]                    if($ni) 
  12.  
  13. [size=; font-size: inherit,inherit]                    { 
  14.  
  15. [size=; font-size: inherit,inherit]                    imagecopyresampled($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH); 
  16. [size=; font-size: inherit,inherit]                    } 
  17. [size=; font-size: inherit,inherit]                    else 
  18. [size=; font-size: inherit,inherit]                    { 
  19. [size=; font-size: inherit,inherit]                    $ni=imagecreate($ftoW,$ftoH); 
  20. [size=; font-size: inherit,inherit]                    imagecopyresized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH); 
  21. [size=; font-size: inherit,inherit]                    } 
  22. [size=; font-size: inherit,inherit]                    } 
  23. [size=; font-size: inherit,inherit]                else 
  24. [size=; font-size: inherit,inherit]                { 
  25. [size=; font-size: inherit,inherit]                    $ni=imagecreate($ftoW,$ftoH); 
  26. [size=; font-size: inherit,inherit]                    imagecopyresized($ni,$im,0,0,0,0,$ftoW,$ftoH,$srcW,$srcH); 
  27. [size=; font-size: inherit,inherit]                } 
  28. [size=; font-size: inherit,inherit]                switch ($srcInfo[2]) 
  29. [size=; font-size: inherit,inherit]                { 
  30. [size=; font-size: inherit,inherit]                    case 1: 
  31. [size=; font-size: inherit,inherit]                    imagegif($ni,$toFile); 
  32. [size=; font-size: inherit,inherit]                    break; 
  33. [size=; font-size: inherit,inherit]                    case 2: 
  34. [size=; font-size: inherit,inherit]                    imagejpeg($ni,$toFile,100); 
  35. [size=; font-size: inherit,inherit]                    break; 
  36. [size=; font-size: inherit,inherit]                    case 3: 
  37. [size=; font-size: inherit,inherit]                    imagepng($ni,$toFile); 
  38. [size=; font-size: inherit,inherit]                    break; 
  39. [size=; font-size: inherit,inherit]                    case 6: 
  40. [size=; font-size: inherit,inherit]                    imagebmp($ni,$toFile); 
  41. [size=; font-size: inherit,inherit]                    break; 
  42. [size=; font-size: inherit,inherit]                    default: 
  43. [size=; font-size: inherit,inherit]                    return false; 
  44. [size=; font-size: inherit,inherit]                } 
  45. [size=; font-size: inherit,inherit]                imagedestroy($ni); 
  46. [size=; font-size: inherit,inherit]            } /// 
  47.  
  48.        $toWH=$toW/$toH; 
  49.        $srcWH=$srcW/$srcH; 
  50.        if($toWH<=$srcWH) 
  51.        { 
  52.             $ftoW=$toW; 
  53.             $ftoH=$ftoW*($srcH/$srcW); 
  54.         } 
  55.         else 
  56.  
  57.         { 
  58.  
  59.             $ftoH=$toH; 
  60.  
  61.             $ftoW=$ftoH*($srcW/$srcH); 
  62.  
  63.        } 
这样织梦上传的图,就不会显示x号了。希望可以帮助到你。

查看更多 DedeCms教程  织梦模板  织梦DedeCms视频教程  织梦dedecms专题

来源:模板无忧//所属分类:DedeCms教程/更新时间:2020-06-05
相关DedeCms教程