POST TIME:2018-02-04 22:27
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,}[sS]{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> |
到此,我們就全部修改好了,內容頁圖片太大導致布局混亂問題就解決了