每次发表带图片的文章,当图片太大时,有时会占了大半个屏幕,对阅读体验非常不好,因为有图片灯箱弹窗,想看图片直接点击图片就行了,所以就不需要默认显示完整图片的大小。所以,今天教大家typecho怎么限制文章内图片的默认大小,改善用户的阅读体验!
具体方法
打开typecho网站根目录下的/var/HyperDown.php,搜索以下代码:
"<img src=\"{$url}\" alt=\"{$escaped}\" title=\"{$escaped}\">"
替换为:
"<img src=\"{$url}\" alt=\"{$escaped}\" title=\"{$escaped}\" style=\"max-width:300px;max-height:400px\" >"
再搜索以下代码:
"<img src=\"{$self->_definitions[$matches[2]]}\" alt=\"{$escaped}\" title=\"{$escaped}\">"
替换为:
"<img src=\"{$self->_definitions[$matches[2]]}\" alt=\"{$escaped}\" title=\"{$escaped}\" style=\"max-width:300px;max-height:400px\" >"
上面的代码限制图片最大高度为400px,最大宽度为300px。可根据自己的需要自定义设置。
本文标签:Typecho