[zblog修改]图片自动缩放功能

本方法来自zblog作者
如何让图片自动缩放以适合界面大小,拿出你的Editplus,打开c_function.asp文件,找到UBBCode函数,在第417行有如下语句

  If Instr(strType,"[image]")>0  And ZC_UBB_IMAGE_ENABLE Then
  '[img]


    objRegExp.Pattern="(\[IMG=)([0-9]*),([0-9]*),(.*)(\])(.+?)(\[\/IMG\])"
    strContent= objRegExp.Replace(strContent,"<img src=""$6"" alt=""$4"" title=""$4"" width=""$2"" height=""$3""/>")

    objRegExp.Pattern="(\[IMG=)([0-9]*),(.*)(\])(.+?)(\[\/IMG\])"
    strContent= objRegExp.Replace(strContent,"<img src=""$5"" alt=""$3"" title=""$3"" width=""$2""/>")

    objRegExp.Pattern="(\[IMG\])(.+?)(\[\/IMG\])"
    strContent= objRegExp.Replace(strContent,"<img src=""$2"" alt="""" title=""""/>")


  End If

在其中加上onload='javascript:if(this.width>400)this.width=400;',这里400是要让超过400的图片小于400,你可以自己设定宽度.比如我的就设置了500

下面是已经改好的

If Instr(strType,"[image]")>0  And ZC_UBB_IMAGE_ENABLE Then
  '[img]

    objRegExp.Pattern="(\[IMG=)([0-9]*),([0-9]*),(.*)(\])(.+?)(\[\/IMG\])"
    strContent= objRegExp.Replace(strContent,"<img onload='javascript:if(this.width>400)this.width=400;' src=""$6"" alt=""$4"" title=""$4"" width=""$2"" height=""$3""/>")

    objRegExp.Pattern="(\[IMG=)([0-9]*),(.*)(\])(.+?)(\[\/IMG\])"
    strContent= objRegExp.Replace(strContent,"<img onload='javascript:if(this.width>400)this.width=400;' src=""$5"" alt=""$3"" title=""$3"" width=""$2""/>")

    objRegExp.Pattern="(\[IMG\])(.+?)(\[\/IMG\])"
    strContent= objRegExp.Replace(strContent,"<img onload='javascript:if(this.width>400)this.width=400;' src=""$2"" alt="""" title=""""/>")


  End If

注意:只有使用了UBB标签[IMG]的才可以实现自动缩放

另外一种是通过js的,适用与大部分模式下自动缩放!
使用: 下载js文件后, 放到\SCRIPT 目录下,并修改TEMPLATE目录下的文件一般只改singel.html,

<div class="post-body"><#Article.Content#>

后加入

<script language="JavaScript" src="../script/img_auto_size.js" type="text/javascript"></script>

然后文件重建

js文件下载

评论

发表新评论

此内容将保密,不会被其他人看见。
  • 可用的 UBB 标签:
  • 留言最长字数:1000。