Get picture width and height of class, support Jpg,gif,png,bmp '

Source: Internet
Author: User
Tags abs

<%
' Get picture width and height of class, support Jpg,gif,png,bmp '
Class Imgwhinfo Dim ASO
Private Sub Class_Initialize
Set aso=server.createobject ("ADODB. Stream ")
ASO. Mode=3
ASO. Type=1
ASO. Open
End Sub
Private Sub Class_Terminate
Err.Clear
Set aso=nothing
End Sub

Private Function bin2str (Bin)
Dim I, Str
For I=1 to LenB (Bin)
CLOW=MIDB (bin,i,1)
If ASCB (Clow) <128 Then
str = str & CHR (ASCB (Clow))
Else
I=i+1
If I <= LenB (Bin) Then str = str & CHR (ASCW (MidB (bin,i,1) &clow))
End If
Next
Bin2str = Str
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,i
Ret = 0
For I=1 to Len (STR)
RET = ret *base + Cint (Mid (str,i,1))
Next
Str2num=ret
End Function

Private Function Binval (Bin)
Dim Ret,i
Ret = 0
For I = LenB (Bin) to 1 Step-1
RET = ret *256 + AscB (MidB (bin,i,1))
Next
Binval=ret
End Function

Private Function BinVal2 (Bin)
Dim Ret,i
Ret = 0
For I = 1 to LenB (Bin)
RET = ret *256 + AscB (MidB (bin,i,1))
Next
Binval2=ret
End Function

Private Function getimagesize (filespec)
Dim Bflag
Dim Ret (3)
ASO. LoadFromFile (filespec)
Bflag=aso. Read (3)
Select Case Hex (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":
Todo
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))
Case Else:
If Left (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) = ""
End If
End Select
RET (3) = "Width=" "" & RET (1) & "" "Height=" "" & Ret (2) & "" "
Getimagesize=ret
End Function

Public Function IMGW (Imgpath)

Dim Fso,imgfile,fileext,arr
Set FSO = Server.CreateObject ("Scripting.FileSystemObject")

If (FSO). FileExists (Imgpath)) Then
Set imgfile = FSO. GetFile (Imgpath)
Fileext=fso. Getextensionname (Imgpath)
Select Case LCase (Fileext)
Case "GIF", "BMP", "JPG", "PNG":
Arr=getimagesize (Imgfile.path)
IMGW = ARR (1)
End Select
Set imgfile=nothing
Else
IMGW = 0
End If
Set fso=nothing
End Function

Public Function IMGH (Imgpath)
Dim Fso,imgfile,fileext,arr
Set FSO = server. CreateObject ("Scripting.FileSystemObject")
If (FSO). FileExists (Imgpath)) Then
Set imgfile = FSO. GetFile (Imgpath)
Fileext=fso. Getextensionname (Imgpath)
Select Case LCase (Fileext)
Case "GIF", "BMP", "JPG", "PNG":
Arr=getimagesize (Imgfile.path)
IMGH = ARR (2)
End Select
Set imgfile=nothing
Else
IMGH = 0
End If
Set fso=nothing
End Function
End Class
%>
How to use:
I. Reference documents:<!--#include file= "picclass.asp"-->
Two
<%
Set PP = New imgwhinfo
Set Fso=server. CreateObject ("Scripting.FileSystemObject")
If FSO. FileExists (server. MapPath (path)) Then ' path is the relative path of the picture file in the server
HH=PP.IMGH (Server.MapPath (path)) ' Get height
WW=PP.IMGW (Server.MapPath (path)) ' Get width
End If
Response.Write ("%> then w=800 End If Response.Write ("")--> =base) ret = (num mod Base) & ret num = (num-num mod Ba SE)/base wend num2str = Right (String (Lens, ' 0 ") & Num & Ret,lens) End Function Private Function str2num (str,base) D im ret,i ret = 0 for I=1 to Len (STR) ret = ret *base + Cint (Mid (str,i,1)) Next Str2num=ret End Function Private function B Inval (BIN) Dim ret,i ret = 0 for I = LenB (bin) to 1 Step-1 ret = ret *256 + AscB (MidB (bin,i,1)) Next Binval=ret End Funct Ion Private Function BinVal2 (bin) Dim ret,i Ret = 0 for I = 1 to LenB (Bin) ret = ret *256 + AscB (MidB (bin,i,1)) Next Binva L2=ret End Function Private Function getimagesize (filespec) Dim bflag Dim Ret (3) ASO. LoadFromFile (filespec) Bflag=aso. Read (3) Select case Hex (Binval (bflag)) case "4E5089": ASO. Read (a) 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) 191 and P1 =base) ret = (num mod base) & ret num = (num-num mod base)/base wend Num2str = Right (String (Lens, "0") & Num & Amp Ret,lens) End Function Private Function str2num (str,base) Dim ret,i ret = 0 for I=1 to Len (STR) ret = ret *base + Cint (Mid (str,i,1)) Next Str2num=ret End Function Private function binval (bin) Dim ret,i ret = 0 for I = LenB (Bin) to 1 Step-1 ret = ret *256 + AscB (MidB (bin,i,1)) Next Binval=ret End Function Private Function BinVal2 (bin) Dim ret,i Ret = 0 for I = 1 to LenB (BIN) RET = ret *256 + AscB (MidB (bin,i,1)) Next Binval2=ret End Function Private function getimagesize (filespec) Dim bflag Dim Ret (3) ASO. LoadFromFile (filespec) Bflag=aso. Read (3) Select case Hex (Binval (bflag)) case "4E5089": ASO. Read (a) 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) 191 and P1 =base) ret = (num mod base) & ret num = (num-num mod base)/base wend Num2str = Right (String (Lens, "0") & Num & Amp Ret,lens) End Function Private Function str2num (str,base) Dim ret,i ret = 0 for I=1 to Len (STR) ret = ret *base + Cint (Mid (str,i,1)) Next Str2num=ret End Function Private function binval (bin) Dim ret,i ret = 0 for I = LenB (Bin) to 1 Step-1 ret = ret *256 + AscB (MidB (bin,i,1)) Next Binval=ret End Function Private Function BinVal2 (bin) Dim ret,i Ret = 0 for I = 1 to LenB (BIN) RET = ret *256 + AscB (MidB (bin,i,1)) Next Binval2=ret End Function Private function getimagesize (filespec) Dim bflag Dim Ret (3) ASO. LoadFromFile (filespec) Bflag=aso. Read (3) Select case Hex (Binval (bflag)) case "4E5089": ASO. Read (a) 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) 191 and P1 =base) ret = (num mod base) & ret num = (num-num mod base)/base wend Num2str = Right (String (Lens, "0") & Num & Amp Ret,lens) End Function Private Function str2num (str,base) Dim ret,i ret = 0 for I=1 to Len (STR) ret = ret *base + Cint (Mid (str,i,1)) Next Str2num=ret End Function Private function binval (bin) Dim ret,i ret = 0 for I = LenB (Bin) to 1 Step-1 ret = ret *256 + AscB (MidB (bin,i,1)) Next Binval=ret End Function Private Function BinVal2 (bin) Dim ret,i Ret = 0 for I = 1 to LenB (BIN) RET = ret *256 + AscB (MidB (bin,i,1)) Next Binval2=ret End Function Private function getimagesize (filespec) Dim bflag Dim Ret (3) ASO. LoadFromFile (filespec) Bflag=aso. Read (3) Select case Hex (Binval (bflag)) case "4E5089": ASO. Read () 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) 191 and P1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.