# dedecms内容页插入图片尺寸大如何不撑开页面的方法

*Published:* 2024-01-10
*Author:* 客服001

#### 温馨提醒

如果文章内容或图片资源失效，请留言反馈，我们会及时处理，谢谢

本文最后更新于2024年1月10日，已超过 180天没有更新



第一步：在img加上便签，还要去掉height属性。

修改[内容页](https://www.xarjtc.com/tag/%e5%86%85%e5%ae%b9%e9%a1%b5 "查看内容页此标签更多文章")模板的{dede:field.body /}为

```
<span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:14px;">{dede:field.body runphp='yes'}
$content = @me;
$mode1 = "/<img/";
$mode2 = "/height=\"(\d+)\" /";
$str1 = "<img onload=\"javascript：ImgReSize(this)\"";
$content = preg_replace($mode1,$str1,$content);
$content = preg_replace($mode2,"",$content);
@me = $content;
{/dede:field.body}</span></span>
```

第二步：将下面代码插入到&lt;head&gt;&lt;/head&gt;中。

注意那个670的数值，这个值意思是当[图片](https://www.xarjtc.com/tag/pic "查看图片此标签更多文章")超过这个数值，自动将图片缩小，宽度缩小为670，高度自动按比例缩小，这样不会变型。

```
<span style="font-family:tahoma,geneva,sans-serif;"><span style="font-size:14px;"><script language='javascript'>
function ImgReSize(e)
{
if(e.width>670) // 670可根据你文章的内容区域大小，可调整
{
e.width=670; // 等同上面你设的那个数值
e.style.;
}
if(e.height>10)
{
e.style.;
}
}
</script></span></span>
```