ASP program to get picture width and height of the class source code

Source: Internet
Author: User
Tags abs chr end
Program | source code | source Code <%
Class Imgwhinfo ' Get a picture of the width and height of classes, support Jpg,gif,png,bmp
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 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 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

Imgpath= "Test.jpg"

Set PP = New imgwhinfo
W = PP.IMGW (Server.MapPath (Imgpath))
H = PP.IMGH (Server.MapPath (Imgpath))
Set pp = Nothing

Response.Write ("<br> width: "&W&"; High: "&h")
%>



Related Article

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.