DEDECMS首页、列表页调用文档首图原图而不是缩略图的实现方法
DEDECMS在上传图片的时候会默认将第一张足够大的图片生成缩略图,这个缩略图无论怎么设置都会在保存文档的时候进行压缩,这样一来图片的清晰度和尺寸都会有所更改。
那么有没有一种方法可以在首页、列表页调用的时候默认提取第一张图片而不是提取缩略图呢?
具体的实现方法经过总结实践,归结如下:
修改include/extend.func.php文件,添加如下代码:
//取第一张图地址function firstimg($str_pic){if(strstr($str_pic,'-lp')){$n=strlen(strstr($str_pic,'-lp'));$str_sub=substr($str_pic,0,-$n).".".substr($str_pic,-3);//删除缩略图字符串最后七位,然后再补上上传文件的后缀}else{$str_sub=$str_pic;}return $str_sub;}
然后在模板里循环时调用:
[field:litpic function=firstimg('@me')/]
直接调用时用:
{dede:field name=’litpic’ function=”firstimg(@me)”/}
至此,我们就已经实现了无论是上传jpg还是png格式的图片都可以默认调用原图而不是处理过的缩略图,对于图片质量有高要求的网站可以采用这种方法,非常的方便。