图片自动保存到本地并利用aspjpeg为图片加水印

2018-09-06 13:21

阅读:644

  <%
函数功能:远程图片自动保存到本地服务器,并利用aspjpeg为图片加上水印
(注意:请先在目录下创建images目录,用来保存临时图片)
本程序需要在服务器上安装aspjpeg组件否则无法正常使用
也可以只取22222222以上的部分,这部分可以保存图片,第二部分是进行水印增加
使用方法,请保存为saveimg.asp
saveimg.asp?url=即可以取下图片啦,HOHO.其他需要加的功能,大家自己扩展好啦
如何获取其他后缀名的文件呢?当然也可以啦
(jpggifpngbmp)改成(mp3)明白吧?就是取mp3后缀的文件名.以此类推.嘻嘻

Server.ScriptTimeOut=99999

constsavepath=images图片保存路径
url=request(url)

functionmyreplace(str)
newstr=str
setobjregEx=newRegExp
objregEx.IgnoreCase=true
objregEx.Global=true
objregEx.Pattern=定义文件后缀
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.openget,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.Family=宋体
Jpeg.Canvas.Font.Bold=True
保存文件
Jpeg.SaveServer.MapPath(saveimg)保存添加水印后的图片

注销对象
SetJpeg=Nothing
endfunction
%>
注意你的服务器组件支持哦.


评论


亲,登录后才可以留言!