ASP Gets the width and height of the image

xiaoxiao2021-03-06  61

Oh, it is necessary for FSO component support, call example:

code:

IMGPATH = "icon_lblog.gif"

Set pp = new imgwhinfo

W = pp.imgw (server.mappath (imgpath))

H = pp.Imgh (server.mappath (imgpath))

Set PP = Nothing

Response.write ("
Wid:" & W & "; High:" & H)

Class code:

code:

<%

Class Imgwhinfo 'Get image width and height class, support JPG, GIF, PNG, BMP

DIM ASO

Private sub coplass_initialize

SET ASO = Server.createObject ("AdoDb.Stream")

Aso.mode = 3

Aso.Type = 1

ASO.OPEN

End Sub

Private sub coplass_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

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 = retend 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)

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)): 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 =" "" "" Height = "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

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

%>

转载请注明原文地址:https://www.9cbs.com/read-84310.html

New Post(0)