asp正则html的图片,对图自动缩放大小
程序员文章站
2022-05-28 16:05:09
下面这个是比较不错的一个复制代码 代码如下:function formatimg2(content) &...
下面这个是比较不错的一个
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);
}
}
复制代码 代码如下:
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);
}
}