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

2018-09-06 12:06

阅读:813

  
今天在站长站看到一网友写的相册程序,功能挺简单的,看到他用了ASPJPEG生成缩略图,不由想起再用上ASPUPLOAD上传,于是花了一个小时时间完善了他的代码。

以下代码均加有简单的注释,如果你看不懂,请先看ASPJPEG以及ASPUPLOAD的说明文档(E文,希望有心理准备),看不懂的可以问我。

以下是代码:

复制代码 代码如下:
<%
ifsession(admin)<>onthen
Response.Redirectlogin.asp
endif
%>
<!--#includefile=config.asp-->
<!--#includefile=mdb/conn.asp-->

<%
SetUpload=Server.CreateObject(Persits.Upload)

FilePath=Server.MapPath(.)

Count=Upload.Save(FilePath&BigPhotoPath)传大图

SmallFilePath=FilePath&SmallPhotoPath

ForEachFileinUpload.Files

SetJpeg=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

ifimgWidth>=imgHeightandimgWidth>120then
Jpeg.Width=150
Jpeg.Height=Jpeg.OriginalHeight/(Jpeg.OriginalWidth/150)
endif
ifimgHeight>imgWidthandimgHeight>113then
Jpeg.Height=113
Jpeg.Width=Jpeg.OriginalWidth/(Jpeg.OriginalHeight/113)
endif
Jpeg.Sharpen1,130
Jpeg.Save(SmallFilePath&S_&File.FileName)


给大图加上水印(仅对大图加水印)
Jpeg.OpenServer.MapPath(&BigFP&)

Jpeg.Canvas.Font.Family=CourierNew

Jpeg.Canvas.Pen.Color=&H000000
Jpeg.Canvas.Pen.Width=2

Jpeg.Canvas.Brush.Solid=False
Jpeg.Canvas.Font.BkMode=Opaque处理平滑

Jpeg.Canvas.PrintText10,10,
Jpeg.Canvas.DrawBar1,1,100,100

Jpeg.SaveServer.MapPath(BigFP)
Next

strSQL=insertintodesktop([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.executestrSQL

setupload=nothing删除对象
typeid=Request.QueryString(typeid)
response.write<SCRIPTlanguage=JavaScript>alert(文件上传成功,返回!);
response.writethis.location.href=addfile.asp?typeid=&typeid&;</SCRIPT>

functionHTMLEncode2(fString)
fString=Replace(fString,CHR(13),)
fString=Replace(fString,CHR(10)&CHR(10),</P><P>)
fString=Replace(fString,CHR(10),<BR>)
HTMLEncode2=fString
endfunction
%>




评论


亲,登录后才可以留言!