Get the height and width of the image (BMP JPG PNG GIF SWF) through AdoDB.Stream

xiaoxiao2021-03-06  39

Get the height and width of the image (BMP JPG PNG GIF SWF) through AdoDB.Stream

When you upload a picture or display SWF, you want to get its height and width basic principles use the adoDb.stream read binary and then parses, then return an array of the first element as the type (BMP JPG PNG GIF SWF) second element is the width of the third element {width} {height} is the height of the fourth element width = {width}, height = {height} for string Class qswhImgdim asoPrivate Sub Class_Initializeset aso = CreateObject ( "Adodb.Stream") aso.Mode = 3 ASO.TYPE = 1 aso.open end subprivate sub class_terminate set aso = Nothingend Sub Private function bin2str (bin) DIM i, Strfor I = 1 to lenb (bin) CLOW = MIDB (BIN, I, 1) IF ASCB (Clow <128 THENSTR = STR & CHR (ASCB (CLOW) ELSEI = I 1IF I <= lenb (bin) THEN STR = STR & CHR (ASCW (MIDB (BIN, I, 1) & CLOW) End ifnext bin2str = Strend FunctionPrivate Function Num2Str (NUM, BAS, LENS) 'qiushuiwuhen (2002-8-12) DIM RETRET = "" While (NUM> = BASE) RET = (Num MOD BASE) & RetNum = (Num - Num MOD BASE) / BaseWendNum2Str = Right (String (Lens, "0") & Num & Ret, lens) End FunctionPrivate Function Str2Num (STR, BASE) 'qiushuiwuhen (2002-8-12) DIM RETRET = 0for i = 1 to Len (STR) RET = RET * BASE CINT (MID (STR, I, 1)) NextStr2Num = Retend FunctionPrivate Function Binval (bin) 'qiushuiwuhen (2002-8-12) di M Retret = 0for i = lenb (bin) to 1 step -1ret = RET * 256 ASCB (MIDB (BIN, I, 1)) Nextbinval = Retend FunctionPrivate Function Binval2 (bin) 'qiushuiwuhen (2002-8-12) DIM Retret = 0for i = 1 to lenb (bin) ret = RET * 256 ASCB (MIDB (BIN, I, 1)) NEXTBINVAL2 = Retend FunctionFunction GetImages (filespec) 'qiushuiwuhen (2002-9-3) DIM RET (3) Aso.LoadFromfile (filespec) bflag = ass (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) 191 and P1 <196 Then Exit do else aso.read (binval2 (ass (2)) - 2) Do: p1 = binval (aso.read (1)): loop while p1 <255 and not based (3) RET (0) = "jpg" RET (2) = binval2 (ASO. READ (2)) RET (1) = binval2 (ASO.READ (2)) Case Else: if Left (Bin2Str (BFLAG), 2) = "BM" THENSO.READ (15) RET (0) = "BMP" Ret (1) = binval (ASO.READ (4)) RET (2) = binval (aso.read (4)) Elseret (0) = "" End Selectret (3) = "width =" "" & Ret (1) & "height =" "" "GetImageSize = retered functionend class use example (width of all pictures under the directory): set qswh = new qswhimg set fso = createObject (" s cripting .FilesystemObject ") set f = fso.getfolder (Server.mAppath (")) SET FC = F.Filesfor Each F1 in fcext = fso.getExtensionName (f1.path) Select Case Extcase "GIF", "BMP", "jpg", "png": arr = qswh.getImageSize (f1.path) response.write "

"& Arr (0) &" & Arr (3) & ":" & F1.Name & "Width:" & Arr (2) Case "SWF" Arr = QSWH. GetImagesize (f1.path) response.write "
" & Arr (0) & "& Arr (3) &": "& f1.name &" width: "& arr (1) &" height: " & arr (2) end selectNextSet fc = nothingSet f = nothingSet fso = nothingSet qswh = nothing