ASP中取得图片宽度和高度的类(无组件)

时间:2021-05-28

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))
Case"4E5089":
ASO.Read(15)
ret(0)="PNG"
ret(1)=BinVal2(ASO.Read(2))
ASO.Read(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"535746":
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)
Case"FFD8FF":
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)="BM"Then
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
Case"gif","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
Case"gif","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)
%>



声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章