<%
'函數功能:遠程圖片自動保存到本地服務器,並利用aspjpeg為圖片加上水印
'(注意:請先在目錄下創建images目錄,用來保存臨時圖片)
'本程序需要在服務器上安裝"aspjpeg組件"否則無法正常使用
'也可以只取'''''22222222'''''''以上的部分,這部分可以保存圖片,第二部分是進行水印增加
'使用方法,請保存為saveimg.asp
'saveimg.asp?url=http://siyizhu.com/logo.gif即可以取下圖片啦,HOHO.其他需要加的功能,大家自己擴展好啦
'如何獲取其他後綴名的文件呢?當然也可以啦
'(jpg|gif|png|bmp)改成(mp3)明白吧?就是取mp3後綴的文件名.以此類推.嘻嘻
Server.ScriptTimeOut=99999
constsavepath="images"'圖片保存路徑
url=request("url")
functionmyreplace(str)
newstr=str
setobjregEx=newRegExp
objregEx.IgnoreCase=true
objregEx.Global=true
objregEx.Pattern="http://(.+?)/.(jpg|gif|png|bmp)"'定義文件後綴
setmatches=objregEx.execute(str)
foreachmatchinmatches
newstr=replace(newstr,match.value,saveimg(match.value))
next
myreplace=newstr
endfunction
functionsaveimg(url)
temp=split(url,".")
'以下是用時間與隨機數重命名文件名
randomize
ranNum=int(90000*rnd)+10000
filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&temp(ubound(temp))
'文件名重命名結束
setxmlhttp=server.createobject("Microsoft.XMLHTTP")
xmlhttp.open"get",url,false
xmlhttp.send
img=xmlhttp.ResponseBody
setxmlhttp=nothing
setobjAdostream=server.createobject("ADODB.Stream")
objAdostream.Open()
objAdostream.type=1
objAdostream.Write(img)
objAdostream.SaveToFile(server.mappath(savepath&filename))
objAdostream.SetEOS
setobjAdostream=nothing
'''''''222222222'''''''''''
saveimg=savepath&filename'獲取保存路徑
DimJpeg
SetJpeg=Server.CreateObject("Persits.Jpeg")
Jpeg.OpenServer.MapPath(saveimg)'打開保存圖片的路徑
'添加文字水印
Jpeg.Canvas.Font.Color=&HFF0000'紅色
Jpeg.Canvas.Font.Family="宋體"
Jpeg.Canvas.Font.Bold=True
Jpeg.Canvas.PrintJpeg.OriginalWidth-200,Jpeg.OriginalHeight-50,"siyizhu.com"'水印離左邊的距離,離頂端的距離,這個是放在右下腳了
'保存文件
Jpeg.SaveServer.MapPath(saveimg)'保存添加水印後的圖片
'註銷對象
SetJpeg=Nothing
endfunction
%>
注意你的服務器組件支持哦.