作家
登录

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

作者: 来源:www.28hudong.com 2013-03-30 08:31:27 阅读 我要评论

下面这个是比较不错的一个复制代码 代码如下: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); } }

  推荐阅读

  asp常用函数集合,非常不错以后研究第1/4页

<% function loadtempletfile(byval path) on error resume next dim objstream set objstream = server.createobject("adodb.stream") with objstream .type = 2 .mode = 3 >>>详细阅读


本文标题:asp正则html的图片,对图自动缩放大小

地址:http://www.17bianji.com/kaifa2/ASP/32307.html

关键词: 探索发现

乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

网友点评
自媒体专栏

评论

热度

精彩导读
栏目ID=71的表不存在(操作类型=0)