利用ASPUPLOAD,ASPJPEG实现图片上传自动生成缩略图及加上水印
程序员文章站
2023-12-05 23:21:58
今天在站长站看到一网友写的相册程序,功能挺简单的,看到他用了aspjpeg生成缩略图,不由想起再用上aspupload上传,于是花了一个小时时间完善了他的代码。 以下代码均...
今天在站长站看到一网友写的相册程序,功能挺简单的,看到他用了aspjpeg生成缩略图,不由想起再用上aspupload上传,于是花了一个小时时间完善了他的代码。
以下代码均加有简单的注释,如果你看不懂,请先看aspjpeg以及aspupload的说明文档(e文,希望有心理准备),看不懂的可以问我。
以下是代码:
复制代码 代码如下:
<%
if session("admin")<>"on" then
response.redirect"login.asp"
end if
%>
<!--#include file="config.asp" -->
<!--#include file="mdb/conn.asp" -->
<%
set upload = server.createobject("persits.upload")
filepath=server.mappath(".")
count = upload.save(filepath&bigphotopath) '传大图
smallfilepath=filepath & smallphotopath
for each file in upload.files
set jpeg = server.createobject("persits.jpeg")
jpeg.open (file.path)
bigfp=bigphotopath&(file.filename) '大图相对路径
sfp=smallphotopath&"s_"&(file.filename)'小图相对路径
filesize=file.size'备写入数据库
'开始判断哪边为长边,以长边进行缩放,并生成小图
imgwidth=jpeg.originalwidth
imgheight=jpeg.originalheight
if imgwidth>=imgheight and imgwidth>120 then
jpeg.width=150
jpeg.height=jpeg.originalheight/(jpeg.originalwidth/150)
end if
if imgheight>imgwidth and imgheight>113 then
jpeg.height=113
jpeg.width=jpeg.originalwidth/(jpeg.originalheight/113)
end if
jpeg.sharpen 1, 130
jpeg.save (smallfilepath&"s_"&file.filename)
'给大图加上水印(仅对大图加水印)
jpeg.open server.mappath(""&bigfp&"")
jpeg.canvas.font.color = &hff0000
jpeg.canvas.font.family = "courier new"
jpeg.canvas.pen.color = &h000000
jpeg.canvas.pen.width = 2
jpeg.canvas.brush.solid = false
jpeg.canvas.font.bkmode = "opaque" '处理平滑
jpeg.canvas.printtext 10, 10, "www.luanluan.cn"
'jpeg.canvas.drawbar 1, 1, 100, 100
jpeg.save server.mappath(bigfp)
next
strsql= "insert into desktop ([name],typeid,zhuanti,jj,[time],imgh,imgw,filesize,url,surl) values ('"&upload.form("name")&"','"&upload.form("typeid")&"','"&upload.form("zhuanti")&"','"&upload.form("photointro")&"','"&now()&"','"&imgheight&"','"&imgwidth&"','"&filesize &"','"&bigfp&"','"&sfp&"')"
conn.execute strsql
set upload=nothing '删除对象
typeid=request.querystring("typeid")
response.write "<script language=javascript>alert('文件上传成功,返回!');"
response.write "this.location.href='addfile.asp?typeid="&typeid&"';</script>"
function htmlencode2(fstring)
fstring = replace(fstring, chr(13), "")
fstring = replace(fstring, chr(10) & chr(10), "</p><p>")
fstring = replace(fstring, chr(10), "<br>")
htmlencode2 = fstring
end function
%>