加入收藏 | 设为首页 | 会员中心 | 我要投稿 银川站长网 (https://www.0951zz.com/)- 云通信、基础存储、云上网络、机器学习、视觉智能!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

asp正则html的图片 对图自主缩放大小

发布时间:2023-07-24 12:54:55 所属栏目:Asp教程 来源:
导读:下面这个是比较不错的一个:代码如下:Function FormatImg2(content) dim re Set re=new RegExp re.IgnoreCase =true re.Global=True re.Pattern="(script)"

下面这个是比较不错的一个:

代码如下:

Function FormatImg2(content) 

           dim re

           Set re=new RegExp

           re.IgnoreCase =true

           re.Global=True

           re.Pattern="(script)"

           Content=re.Replace(Content,"script")

           re.Pattern="<img.[^>]*src(=| )(.[^>]*)>"

         Content=re.replace(Content,"<img src=$2  style=""cursor: pointer"" alt=""点此在新窗口浏览图片"" onclick=""javascript:window.open(this.src);"" onload=""javascript:resizepic(this)"" border=""0""/>")

          set re = nothing

          FormatImg = content

        end function

上面有点不好的就是对于图片中的宽度和高度都不存在了

代码如下:

Function getphoto(strHTML) 

Dim objRegExp, Match, Matches 

Set objRegExp = New Regexp

objRegExp.IgnoreCase = True 

objRegExp.Global = True 

objRegExp.Pattern = "<img.+?>" 

tp=""

Set Matches = objRegExp.Execute(strHTML)

For Each Match in Matches 

tp=tp & Match.value 

exit for

Next 

getphoto=tp

Set objRegExp = Nothing 

End Function

下面的代码时进行图片按比例缩放

代码如下:

function ResizeImage(imageid,limitWidth,limitHeight) 

{     

    var image = new Image(); 

    image.src = imageid.src; 

 

    if(image.width <= 0 && image.height <= 0) return; 

 

    if(image.width/image.height >= limitWidth/limitHeight) 

    { 

        if(image.width > limitWidth) 

        { 

            imageid.width = limitWidth; 

            imageid.height = (image.height*limitWidth)/image.width; 

(编辑:银川站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章