今天在站長(zhǎng)站看到一網(wǎng)友寫(xiě)的相冊(cè)程序,功能挺簡(jiǎn)單的,看到他用了ASPJPEG生成縮略圖,不由想起再用上ASPUPLOAD上傳,于是花了一個(gè)小時(shí)時(shí)間完善了他的代碼。
以下代碼均加有簡(jiǎn)單的注釋?zhuān)绻憧床欢?,?qǐng)先看ASPJPEG以及ASPUPLOAD的說(shuō)明文檔(E文,希望有心理準(zhǔn)備),看不懂的可以問(wèn)我。
以下是代碼:
復(fù)制代碼 代碼如下:
%
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(FilePathBigPhotoPath) '傳大圖
SmallFilePath=FilePath SmallPhotoPath
For Each File in Upload.Files
Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.Open (File.Path)
BigFP=BigPhotoPath(File.FileName) '大圖相對(duì)路徑
SFP=SmallPhotoPath"S_"(File.FileName)'小圖相對(duì)路徑
FileSize=File.Size'備寫(xiě)入數(shù)據(jù)庫(kù)
'開(kāi)始判斷哪邊為長(zhǎng)邊,以長(zhǎng)邊進(jìn)行縮放,并生成小圖
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)
'給大圖加上水印(僅對(duì)大圖加水印)
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 '刪除對(duì)象
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
%>
您可能感興趣的文章:- Asp無(wú)組件生成縮略圖的代碼
- ASP保存遠(yuǎn)程圖片到本地 同時(shí)取得第一張圖片并創(chuàng)建縮略圖的代碼
- ASP.Net 上傳圖片并生成高清晰縮略圖
- asp.net 自定義控件實(shí)現(xiàn)無(wú)刷新上傳圖片,立即顯示縮略圖,保存圖片縮略圖
- Asp.Net平臺(tái)下的圖片在線裁剪功能的實(shí)現(xiàn)代碼(源碼打包)
- ASP組件AspJpeg(加水印)生成縮略圖等使用方法
- asp.net 圖片超過(guò)指定大小后等比例壓縮圖片的方法
- ASP.NET簡(jiǎn)單好用功能齊全圖片上傳工具類(lèi)(水印、縮略圖、裁剪等)
- ASP固定比例裁剪縮略圖的方法