asp正則html的圖片,對圖自動縮放大小
更新時間:2008年03月06日 10:19:14 作者:
下面的代碼是從html中正則取出圖片,然后批量替換等
下面這個是比較不錯的一個
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);
}
}
復(fù)制代碼 代碼如下:
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
上面有點不好的就是對于圖片中的寬度和高度都不存在了
復(fù)制代碼 代碼如下:
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
下面的代碼時進行圖片按比例縮放
復(fù)制代碼 代碼如下:
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);
}
}
相關(guān)文章
ASP 包含文件中的路徑問題和使用單一數(shù)據(jù)庫連接文件的解決方案
全站只需要用一個數(shù)據(jù)庫連接文件的實現(xiàn)函數(shù)代碼2009-03-03Asp 操作Cookies(包括設(shè)置[賦值]、讀取、刪除[設(shè)置過期時間])
Asp 操作Cookies(包括設(shè)置[賦值]、讀取、刪除[設(shè)置過期時間]) ,這個是比較全的了,更多資料可以參考腳本之家前兩篇文章。2010-03-03ASP是使用正則提取內(nèi)容里所有圖片路徑SRC的實現(xiàn)代碼
有時候客戶提交的內(nèi)容里包含多個圖片,客戶想單獨把圖片路徑提取出來進行保存,下面腳本之家小編跟大家分享ASP正則提取內(nèi)容里所有圖片路徑SRC的方法函數(shù),需要的朋友可以參考下2019-09-09ASP中用ajax方式獲得session的實現(xiàn)代碼
前期做的時候,登錄方式順手用了ajax來做,登錄前先判斷在session中是否存在值,如果存在,那么無需登錄;如果不存在,那就彈出登錄頁面登錄。2011-05-05用ASP VBS xmlhttp adodbstream下載和保存圖片的代碼
用ASP VBS xmlhttp adodbstream下載和保存圖片的代碼...2007-03-03ASP Eval、Execute、ExecuteGlobal區(qū)別分析
Eval、Execute、ExecuteGlobal 這三個語句(函數(shù))都是執(zhí)行字符串表達式,不過它們之間又有所不同。2011-07-07一個能對訪問者進行編號、記錄訪問次數(shù)、IP、時間的統(tǒng)計制作實例
一個能對訪問者進行編號、記錄訪問次數(shù)、IP、時間的統(tǒng)計制作實例...2006-12-12