Today, I saw a photo album program written by a netizen on the webmaster website. The function was quite simple. When he saw that he used ASPJPEG to generate thumbnails, he couldn't help but think of using ASPUPLOAD to upload it, so he spent an hour to perfect his code.
All the following codes are given simple comments. If you can't understand, please read the instructions for ASPJPEG and ASPUPLOAD first (E-text, I hope you are mentally prepared). If you don't understand, you can ask me.
Here is the code:
The code copy is as follows:
<%
ifsession("admin")<>"on"then
Response.Redirect"login.asp"
endif
%>
<!--#includefile="config.asp"-->
<!--#includefile="mdb/conn.asp"-->
<%
SetUpload=Server.CreateObject("Persits.Upload")
FilePath=Server.MapPath(".")
Count=Upload.Save(FilePath&BigPhotoPath)'Transfer large image
SmallFilePath=FilePath&SmallPhotoPath
ForEachFileinUpload.Files
SetJpeg=Server.CreateObject("Persits.Jpeg")
Jpeg.Open(File.Path)
BigFP=BigPhotoPath&(File.FileName)'Large image relative path
SFP=SmallPhotoPath&"S_"&(File.FileName)' small picture relative path
FileSize=File.Size' is ready to write to the database
'Start to determine which side is the long side, scale with the long side, and generate a small picture
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)
'Add a watermark to the large image (only add a watermark to the large image)
Jpeg.OpenServer.MapPath("&BigFP&"")
Jpeg.Canvas.Font.Color=&HFF0000
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"' handles smoothing
Jpeg.Canvas.PrintText10,10,"www.LuanLuan.cn"
'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&"')"