主页 > 知识库 > asp正则html的图片,对图自动缩放大小

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

热门标签:科大讯飞语音识别系统 Mysql连接数设置 银行业务 Linux服务器 电子围栏 服务器配置 团购网站 阿里云
下面这个是比较不错的一个
复制代码 代码如下:

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; 
        } 
    } 
    else if(image.height > limitHeight) 
    { 
            imageid.height = limitHeight; 
            imageid.width = (image.width*limitHeight)/image.height;      
    } 

    if (imageid.parentElement.tagName != "A") 
    { 
        imageid.onclick = function(){window.open(this.src);} 
        imageid.style.cursor = "hand"; 
    } 


window.onload = InitImages;
function InitImages() 

//图片的约束宽度和高度
   var maxWidth = 100; 
    var maxHeight = 100; 
    var imgs = document.getElementsByTagName("img"); 
    for(var i=0; i  imgs.length; i++) 
    { 
        var img = imgs; 
        if(img.width>maxWidth||img.height>maxHeight) 
            ResizeImage(img, maxWidth, maxHeight); 
    } 
}
您可能感兴趣的文章:
  • javascript图片自动缩放和垂直居中处理函数
  • CSS expression控制图片自动缩放效果代码[兼容 IE,Firefox]
  • 兼容ie、firefox的图片自动缩放的css跟js代码分享

标签:江苏 衢州 大理 蚌埠 萍乡 衡水 广元 枣庄

巨人网络通讯声明:本文标题《asp正则html的图片,对图自动缩放大小》,本文关键词  ;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 收缩
    • 微信客服
    • 微信二维码
    • 电话咨询

    • 400-1100-266