DEDECMS图片撑破布局的解决方法
DEDECMS内容页图片过大,我们又不希望它不按比例的缩小,因为如果缩小不按比例,图片就会变形,所以我们需要找到一种等比例缩放图片的方法。
第一步:打开include/arc.archives.class.php
找到:
//设置全局环境变量$this->Fields['typename'] = $this->TypeLink->TypeInfos['typename'];@SetSysEnv($this->Fields['typeid'],$this->Fields['typename'],$this->Fields['id'],$this->Fields['title'],'archives'); 在下面加入代码:
//替换图片Alt为文档标题$this->Fields['body'] = str_ireplace(array('alt=""','alt='''),'',$this->Fields['body']);$this->Fields['body'] = preg_replace("@ {0,}alt{0,}=["'s]{0,}{0,}["'s]@isU"," ",$this->Fields['body']);$this->Fields['body'] = str_ireplace("<img " ,"<img alt="".$this->Fields['title'].""",$this->Fields['body']);//img标签中加入超宽缩小JS调用代码$suolue='onload="javascript:ImgReSize(this)"';$this->Fields['body'] = str_ireplace("<img " ,"<img ".$suolue." ",$this->Fields['body']);//屏蔽height属性$this->Fields['body'] = preg_replace('/<img(.+?)height=(.+?) (.+?)>/i',"<img$1$3>",$this->Fields['body']); 第二步:打开你前台文章页模版,默认的是:/templets/default/article_article.htm,加入如下代码。那个600的数值,意思是当图片超过这个数值,自动将图片缩小,宽度缩小为600,高度自动按比例缩小,这样不会变形。
<script language='javascript'>function ImgReSize(e){if(e.width>600) //600可根据你文章的内容区域大小,可调整{ e.width=600; //等同上面你设的那个数值 e.style.width="";}if(e.height>10){ e.style.height="";}}</script> 到此,我们就全部修改好了,内容页图片太大导致布局混乱问题就解决了。
页:
[1]