<%
‘函數(shù)功能:遠(yuǎn)程圖片自動(dòng)保存到本地服務(wù)器,并利用aspjpeg為圖片加上水印
‘(注意:請(qǐng)先在目錄下創(chuàng)建images目錄,用來保存臨時(shí)圖片)
Server.ScriptTimeOut=99999
const savepath="images" ‘圖片保存路徑
url=request("url")
function myreplace(str)
newstr=str
set objregEx = new RegExp
objregEx.IgnoreCase = true
objregEx.Global = true
objregEx.Pattern = "http://(.+?)\.(jpg|gif|png|bmp)" ‘定義文件后綴
set matches = objregEx.execute(str)
for each match in matches
newstr=replace(newstr,match.value,saveimg(match.value))
next
myreplace=newstr
end function
function saveimg(url)
temp=split(url,".")
‘以下是用時(shí)間與隨機(jī)數(shù)重命名文件名
randomize
ranNum=int(90000*rnd)+10000
filename=year(now)&month(now)&day(now)&hour(now)&minute(now)&second(now)&ranNum&"."&temp(ubound(temp))
‘文件名重命名結(jié)束
set xmlhttp=server.createobject("Microsoft.XMLHTTP")
xmlhttp.open "get",url,false
xmlhttp.send
img=xmlhttp.ResponseBody
set xmlhttp=nothing
set objAdostream=server.createobject("ADODB.Stream")
objAdostream.Open()
objAdostream.type=1
objAdostream.Write(img)
objAdostream.SaveToFile(server.mappath(savepath&filename))
objAdostream.SetEOS
set objAdostream=nothing
‘水印部分
saveimg=savepath&filename ‘獲取保存路徑
Dim Jpeg
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.Open Server.MapPath(saveimg) ‘打開保存圖片的路徑
‘ 添加文字水印
Jpeg.Canvas.Font.Color = &HFF0000‘ 紅色
Jpeg.Canvas.Font.Family = "宋體"
Jpeg.Canvas.Font.Bold = True
Jpeg.Canvas.Print Jpeg.OriginalWidth-200,Jpeg.OriginalHeight-50, "siyizhu.com" ‘水印離左邊的距離,離頂端的距離,這個(gè)是放在右下腳了
‘保存文件
Jpeg.Save Server.MapPath(saveimg) ‘保存添加水印后的圖片
‘ 注銷對(duì)象
Set Jpeg = Nothing
end function
%>
聯(lián)系客服