当前位置: 首页 > 图文教程 > 网络编程 > ASP > 利用ASPUPLOAD,ASPJPEG实现图片上传自动生成缩略图及加上水印

ASP
ASP字符串大写转换成小写 ASP小写转换成大写 ucase lcase
asp base64加解密函数代码
Discuz!NT 论坛整合ASP程序论坛
discuz 2.0整合asp系统,用户添加函数
P3P 和 跨域 (cross-domain) cookie 访问(读取和设置)
通过asp程序来创建access数据库
检查access数据库中是否存在某个名字的表的asp代码
asp #include file 与 #include virtual 的区别小结
一个带采集远程文章内容,保存图片,生成文件等完整的采集功能
asp 横排显示数据
asp base64 utf-8为了兼容asp.net的base64
两个非常规ASP木马(可躲过扫描)
asp DateDiff实现文字在特定时间后消失
ASP所有的Session变量获取实现代码
关于ASP eof与bof 区别分析
asp ajax注册验证之 防止用户名输入空格
asp sqlserver 执行存储过程返回记录集报对象关闭时不允许操作
ASP 获取文件扩展名函数getFileExt()
asp 简单分页代码
asp删除mssql数据库中没有记录的图片代码

利用ASPUPLOAD,ASPJPEG实现图片上传自动生成缩略图及加上水印


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-12   浏览: 71 ::
收藏到网摘: n/a


今天在站长站看到一网友写的相册程序,功能挺简单的,看到他用了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("/upload/tech/20091012/20091012012131_c51ce410c124a10e0db5e4b97fc2af39.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
%>