Today, I saw a photo album program written by a netizen on the webmaster's website. The function was quite simple. I saw that he used ASPJPEG to generate a thumbnail. Instead of remembering to upload it with ASPUPLOAD, so it took an hour to complete his code.
The following code adds simple comments. If you do not understand the code, please read the ASPJPEG and ASPUPLOAD instructions (E, hope to be prepared). If you do not understand the code, please ask me.
The following code is used:
Copy codeThe Code is as follows: <%
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) 'relative path of the image
FileSize = File. Size 'backup is written to the database
'Start to determine which side is a long edge, scale with the long side, and generate a small image
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)
'Add a watermark to the big image (only add a watermark to the big image)
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" 'Smooth Processing
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.exe cute strSQL
Set upload = nothing 'delete an object
Typeid = Request. QueryString ("typeid ")
Response. write "<SCRIPT language = JavaScript> alert ('file uploaded successfully, return! ');"
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
%>