<%
'------------------------------ GetSize.asp ------------------------------
'File Build Date: 2004-08-14
'ImgPath文件路径,要求绝对路径。ImgWidth图片约束宽度,ImgHeight图片约束高度
'函数返回值为一个5个元素的数组,下面是数组元素返回值的意义
'Array(0):图片类型。只会返回GIF或JPG两种类型,否则就返回空串
'Array(1):约束后的图片宽度
'Array(2):约束后的图片高度
'Array(3):图片原宽度
'Array(4):图片原高度
Function ImgSize(ImgPath,ImgWidth,ImgHeight)
dim ret(5)
Set ASO = Server.CreateObject("Adodb.Stream")
ASO.Mode = 3
ASO.Type = 1
ASO.Open
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
If Not FSO.FileExists(ImgPath) Then
Ret(0) = ""
Ret(1) = 0
Ret(2) = 0
Ret(3) = 0
Ret(4) = 0
ImgSize = Ret
Set FSO = Nothing
FSO = Empty
ASO.Close
Set ASO = Nothing
ASO = Empty
Exit Function
End If
Set FSO = Nothing
FSO = Empty
ASO.LoadFromFile(ImgPath)
bFlag=ASO.Read(3)
If hex(BinVal(bFlag)) = "FFD8FF" Then
Do
Do: p1=BinVal(aso.Read(1)): Loop While p1=255 And Not aso.EOS
If p1>191 And p1<196 Then Exit Do Else aso.Read(BinVal2(aso.Read(2))-2)
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))
Ret(3) = Ret(1)
Ret(4) = Ret(2)
ElseIf Hex(BinVal(bFlag)) = "464947" Then
aso.Read(3)
Ret(0) = "GIF"
Ret(1) = BinVal(aso.Read(2))
Ret(2) = BinVal(aso.Read(2))
Ret(3) = Ret(1)
Ret(4) = Ret(2)
Else
Ret(0) = ""
Ret(1) = 0
Ret(2) = 0
Ret(3) = Ret(1)
Ret(4) = Ret(2)
End If
If Ret(0) <> "" Then
BS = 1
If IsNumeric(ImgWidth) And IsNumeric(ImgHeight) Then
If ImgWidth > 0 And ImgHeight > 0 Then
BS = Ret(1)/ImgWidth
If BS < Ret(2)/ImgHeight Then BS = Ret(2)/ImgHeight
If BS < 1 Then BS = 1
End If
End If
Ret(1) = Ret(1)/BS
Ret(2) = Ret(2)/BS
End If
ImgSize = Ret
ASO.Close
Set ASO = Nothing
ASO = Empty
End Function
Private Function BinVal(bin)
dim ret
Ret = 0
For ImgSizeI = lenb(bin) to 1 step -1
Ret = ret *256 + ascb(midb(bin,ImgSizeI,1))
Next
BinVal=ret
End Function
Private Function BinVal2(bin)
Dim ret
ret = 0
For ImgSizeI = 1 To lenb(bin)
ret = ret *256 + ascb(midb(bin,ImgSizeI,1))
Next
BinVal2=ret
End Function
%>