今天在站長站看到一網友寫的相冊程序,功能挺簡單的,看到他用了ASPJPEG生成縮略圖,不由想起再用上ASPUPLOAD上傳,於是花了一個小時時間完善了他的代碼。
以下代碼均加有簡單的註釋,如果你看不懂,請先看ASPJPEG以及ASPUPLOAD的說明文檔(E文,希望有心理準備),看不懂的可以問我。
以下是代碼:
複製代碼代碼如下:
<%
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)'傳大圖
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.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"'處理平滑
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&"')"