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("@ [\s]{0,}alt[\s]{0,}=[\"'\s]{0,}[\s\S]{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']); |
<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> |
到此,我们就全部修改好了,内容页图片太大导致布局混乱问题就解决了