ASP中取得图片宽度和高度的类(无组件)
2018-09-06 12:09
ASP中取得图片宽度和高度的类(无组件)
<%
ClassImgWHInfo获取图片宽度和高度的类,支持JPG,GIF,PNG,BMP
DimASO
PrivateSubClass_Initialize
SetASO=Server.CreateObject(ADODB.Stream)
ASO.Mode=3
ASO.Type=1
ASO.Open
EndSub
PrivateSubClass_Terminate
Err.Clear
SetASO=Nothing
EndSub
PrivateFunctionBin2Str(Bin)
DimI,Str
ForI=1ToLenB(Bin)
clow=MidB(Bin,I,1)
IfASCB(clow)<128Then
Str=Str&Chr(ASCB(clow))
Else
I=I+1
IfI<=LenB(Bin)ThenStr=Str&Chr(ASCW(MidB(Bin,I,1)&clow))
EndIf
Next
Bin2Str=Str
EndFunction
PrivateFunctionNum2Str(Num,Base,Lens)
DimRet
Ret=
While(Num>=Base)
Ret=(NumModBase)&Ret
Num=(Num-NumModBase)/Base
Wend
Num2Str=Right(String(Lens,0)&Num&Ret,Lens)
EndFunction
PrivateFunctionStr2Num(Str,Base)
DimRet,I
Ret=0
ForI=1ToLen(Str)
Ret=Ret*base+Cint(Mid(Str,I,1))
Next
Str2Num=Ret
EndFunction
PrivateFunctionBinVal(Bin)
DimRet,I
Ret=0
ForI=LenB(Bin)To1Step-1
Ret=Ret*256+AscB(MidB(Bin,I,1))
Next
BinVal=Ret
EndFunction
PrivateFunctionBinVal2(Bin)
DimRet,I
Ret=0
ForI=1ToLenB(Bin)
Ret=Ret*256+AscB(MidB(Bin,I,1))
Next
BinVal2=Ret
EndFunction
PrivateFunctionGetImageSize(filespec)
DimbFlag
DimRet(3)
ASO.LoadFromFile(filespec)
bFlag=ASO.Read(3)
SelectCaseHex(binVal(bFlag))
Case4E5089:
ASO.Read(15)
ret(0)=PNG
ret(1)=BinVal2(ASO.Read(2))
ASO.Read(2)
ret(2)=BinVal2(ASO.Read(2))
Case464947:
ASO.read(3)
ret(0)=gif
ret(1)=BinVal(ASO.Read(2))
ret(2)=BinVal(ASO.Read(2))
Case535746:
ASO.read(5)
binData=ASO.Read(1)
sConv=Num2Str(ascb(binData),2,8)
nBits=Str2Num(left(sConv,5),2)
sConv=mid(sConv,6)
While(len(sConv)<nBits*4)
binData=ASO.Read(1)
sConv=sConv&Num2Str(AscB(binData),2,8)
Wend
ret(0)=SWF
ret(1)=Int(Abs(Str2Num(Mid(sConv,1*nBits+1,nBits),2)-Str2Num(Mid(sConv,0*nBits+1,nBits),2))/20)
ret(2)=Int(Abs(Str2Num(Mid(sConv,3*nBits+1,nBits),2)-Str2Num(Mid(sConv,2*nBits+1,nBits),2))/20)
CaseFFD8FF:
Do
Do:p1=binVal(ASO.Read(1)):LoopWhilep1=255AndNotASO.EOS
Ifp1>191Andp1<196ThenExitDoElseASO.read(binval2(ASO.Read(2))-2)
Do:p1=binVal(ASO.Read(1)):LoopWhilep1<255AndNotASO.EOS
LoopWhileTrue
ASO.Read(3)
ret(0)=JPG
ret(2)=binval2(ASO.Read(2))
ret(1)=binval2(ASO.Read(2))
CaseElse:
Ifleft(Bin2Str(bFlag),2)=BMThen
ASO.Read(15)
ret(0)=BMP
ret(1)=binval(ASO.Read(4))
ret(2)=binval(ASO.Read(4))
Else
ret(0)=
EndIf
EndSelect
ret(3)=width=&ret(1)&height=&ret(2)&
getimagesize=ret
EndFunction
PublicFunctionimgW(IMGPath)
DimFSO,IMGFile,FileExt,Arr
SetFSO=Server.CreateObject(Scripting.FileSystemObject)
If(FSO.FileExists(IMGPath))Then
SetIMGFile=FSO.GetFile(IMGPath)
FileExt=FSO.GetExtensionName(IMGPath)
SelectCaseFileExt
Casegif,bmp,jpg,png:
Arr=GetImageSize(IMGFile.Path)
imgW=Arr(1)
EndSelect
SetIMGFile=Nothing
Else
imgW=0
EndIf
SetFSO=Nothing
EndFunction
PublicFunctionimgH(IMGPath)
DimFSO,IMGFile,FileExt,Arr
SetFSO=server.CreateObject(Scripting.FileSystemObject)
If(FSO.FileExists(IMGPath))Then
SetIMGFile=FSO.GetFile(IMGPath)
FileExt=FSO.GetExtensionName(IMGPath)
SelectCaseFileExt
Casegif,bmp,jpg,png:
Arr=getImageSize(IMGFile.Path)
imgH=Arr(2)
EndSelect
SetIMGFile=Nothing
Else
imgH=0
EndIf
SetFSO=Nothing
EndFunction
EndClass
IMGPath=next.gif
SetPP=NewImgWHInfo
W=PP.imgW(Server.Mappath(IMGPath))
H=PP.imgH(Server.Mappath(IMGPath))
Setpp=Nothing
Response.Write(<imgsrc=&IMGPath&border=0><br>宽:&W&;高:&H)
%>
文章标题:ASP中取得图片宽度和高度的类(无组件)
文章链接:http://soscw.com/index.php/essay/10042.html