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']);
第二步:打开你前台文章页模版,默认的是:/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>
到此,我们就全部修改好了,内容页图片太大导致布局混乱问题就解决了。

![[工具]ARCHPR4.53明文攻击 vulsee.com-微慑信息网-VulSee.com](https://vulsee.com/wp-content/uploads/2024/08/8b73b3a0d12a4f128f8b6c8847cbd414.png)

![[vulsee] TinyPNG测试-微慑信息网-VulSee.com](https://vulsee.com/wp-content/uploads/2023/11/56acb049166c9da5380e6a02eb682f86.png)

![[文件分割工具]hjsplit - vulsee.com-微慑信息网-VulSee.com](https://vulsee.com/wp-content/uploads/2023/04/b26650c29959c9bca95b386a71d6ede6.png)






![[八卦] 王婷婷—揭秘一个大三女生的性爱录像-微慑信息网-VulSee.com](http://free.86hy.com/crack/pic/1.jpg)
![[随笔]今天国际警察节-微慑信息网-VulSee.com](http://photo.sohu.com/20041017/Img222528326.jpg)

青云网
