不使用组件如何自动生成JPG缩略图?
现在做一个页面需要很多图片。问题是服务器上没有图片组件。仅仅是FSO和ADO。请问有没有办法用ASP 自动生成一个小的图片?否则一个页面下载的太慢了。
附下面的代码是获取图片文件的宽和高的
程序代码:
<% Class DealImgSize Dim aso ' 初始化 Private Sub Class_Initialize Set aso = CreateObject("ADODB.Stream") aso.Mode = 3 aso.Type = 1 aso.Open End Sub '结束对象 Private Sub Class_Terminate Set aso =Nothing End Sub Private Function Bin2Str(Bin) Dim i,str, clow For i =1 to LenB(Bin) '字节长度,Unicode是双字节的 clow =MidB(Bin,i,1) '取得i开始的1个字节 If AscB( clow ) < 128 Then '如果首字节的ascii码小于128则将其放入到str字符串中 str = str & Chr(ASCB( clow )) Else i = i + 1 '如果当前大于等于128,则处理下一个 If i <= LenB(Bin ) Then str = str & Chr(ASCW(Mid(Bin,i,1)&clow)) End If Next End Function Private Function Num2Str(num,base,lens) Dim ret ret = "" While (num >=base ) ret = (num mod base ) &ret num = (num - (num mod base)/base Wend Num2Str = Right(String(lens,"0")&num&ret,lens) End Function Private Function Str2Num(str,base) Dim ret ret = 0 For i = 1 To len(str) ret = ret * base + Cint (Mid(str,i,1)) Next Str2Num = ret End Function ' 将bin按字节使用ASCII编码返回(倒序) Private Function BinVal( bin ) Dim ret ret = 0 For i = lenb( bin ) to 1 step -1 ret = ret * 256 + ascb(midb(bin,i,1)) Next BinVal = ret End Function ' 将bin按字节使用ASCII编码返回 Private Function BinVal2( bin ) Dim ret For i =1 To lenb(bin) ret = ret*256 + Ascb(Midb(bin , i , 1) ) Next BinVal2 = ret End Function ' 以下是调用代码 Function getImageSize( filespec ) Dim ret(3) aso.LoadFromFile ( filespec ) bFlag = aso.read(3) Select Case hex(BinVal(bFlag)) case "4E5089": 'PNG图前3个字节 是 89 50 4E aso.read(15) ret(0) = "PNG" ret(1) = BinVal2(aso.Read(2)) '读取宽度 aso.Read(2) '空2个字节 ret(2) = BinVal2(aso.Read(2)) '读取高度 Case "464947": aso.Read(3) ret(0) = "GIF" ret(1) = BinVal(aso.Read(2)) ret(2) = BinVal(aso.Read(2)) Case "FFD8FF": Do Do p1 = BinVal( aso.Read(1) ) Loop While p1 = 255 And Not aso.EOS '如果是FF就继续读下一个字节 If p1>191 and p1 < 196 Then '如果是C0,C1,C2,C3则 退出 Exit Do Else aso.Read( BinVal2(aso.Read(2))-2) End If Do p1 = binVal(aso.Read(1)) Loop While p1<255 And Not aso.EOS Loop While True aso.Read(3) ret(0) = "JPG" ret(2) = BinVal2( aso.Read(2)) ret(1) = BinVal2( aso.Read(2)) End Select ret(3) = "width="""& ret(1) & """ heigth= """& ret(2) & """ getImageSize = ret End Function End Class %>
[ 本帖最后由 willstier 于 2010-3-9 13:22 编辑 ]