Use FSO to get BMP, JPG, PNG, GIF file information

zhaozj2021-02-16  72

<%

': :::::::::::::::::::::::::: ::::::::::::::::::

': :::::::::::::::::::::::::: ::::::::::::::::::

'::: BMP, GIF, JPG and PNG :::

':::: Original: junyd ::::::::::

'::::: ::::::::::::::::::::::::::: :::

'::: :::

':: This Dongdong can get this file from BMP, GIF, JPG and PNG picture :::

': :::::::::::::::::::::::::: ::::::::::::::::::

Function getBytes (flnm, offset, bytes)

DIM OBJFSO

DIM Objftemp

DIM ObjTextStream

Dim lngsize

ON Error ResMe next

Set objfso = creteObject ("scripting.filesystemobject")

'First, we get FileSize

Set objftemp = objfso.getfile (flnm)

LNGSIZE = Objftemp.size

Set objftemp = Nothing

FsoForReading = 1

Set objTextStream = objfso.opentextfile (flnm, fsoforreading)

IF offset> 0 THEN

Strbuff = ObjtextStream.read (Offset - 1)

END IF

iftes = -1 Then 'get all!

GetBytes = ObjtextStream.Read (LNGSIZE) 'Readall

Else

GetBytes = ObjTextStream.read (bytes)

END IF

ObjtextStream.close

Set objtextStream = Nothing

Set objfso = Nothing

END FUNCTION

': :::::::::::::::::::::::::: :::::::::::::: ': ::: :::' :: ::: ':::: (Small endian and big endian) ::: '::::::::::::::::::: :::::::::::::::::::::::::::::::::::::th " 1)) ((ASC (Right (straTemp, 1)) * 256))))))))) End FunctionFunction LNGCONVERT2 (STRTEMP) LNGCONVERT2 = ClNG (ASC (Right (strTemp, 1)) ((ASC (strave (straTemp, 1) )) * 256))) End function ': ::::::::::::::::::::::: ::::::::::::::::::::::::::::: '::::::' ::: This function makes most real work.

It is willing to try ::: '::: Read any file :::' ::: If it is an image of a chart, identification. ::: '::: :::' :::pased: ::: '::: File to read :::' ::: => width of image ::: => => height of image ::: '::: Depth => color depth (in Number of Colors) ::: '::: StrimageType => Type of Image (EG GIF, BMP, etc.) :::' ::: ::: ':::::::::' ::::::::: ::::: :::::::::::::::::::::: :::::: function gfxSpex (flnm, width, height, depth, strImageType) dim strPNG dim strGIFdim strBMPdim strTypestrType = "" strImageType = "(unknown)" gfxSpex = FalsestrPNG = chr (137) & chr (80) & chr (78) strgif = "gif" strbmp = chr (66) & chr (77) strtype = getBytes (flnm, 0, 3) if strtype = strgif kilns gifstrimageType = "gif" width = LNGCONVERT (GetBytes (FLNM, 7) 2)) Height = LNGCONVERT (Gettes (FLNM, 9, 2)) DEPTH = 2 ^ ((ASC (Gettes (FLNM, 11, 1)) and 7) 1) gfxspex = trueelseif left (strueelseif left (strType, 2) = Strbmphen 'is bmpstrimageType = "bmp" width = lcomconvert (GetBytes (FLNM, 19, 2)) HEIGHT = LNGCONVERT (GetBytes (FLNM, 23, 2)) Depth = 2 ^ (ASC (Gettes (f LNM, 29, 1))) GFXSPEX = Trueelseif Strtype = strpng the 'is pngstrimageType = "PNG" width = LNGCONVERT2 (GetBytes (FLNM, 19, 2)) Height = LNGCONVERT2 (GetBytes (FLNM, 23, 2)) DEPTH = Gettes (FLNM, 25, 2) SELECT CASE ASC (Right (depth, 1)) Case 0Depth = 2 ^ (ASC (Left (depth, 1))) GFXSPEX = truecase 2Depth = 2 ^ (ASC (LEFT (Depth, 1 )) * 3) gfxspex = truecase 3Depth = 2 ^ (ASC (defrm (defth, 1))) '8GFXSPEX = truecase 4Depth = 2 ^ (ASC (LEFT (DEPTH, 1)) * 2) GFXSPEX =

Truecase 6Depth = 2 ^ (asc (left (Depth, 1)) * 4) gfxSpex = Truecase elseDepth = -1end selectelsestrBuff = GetBytes (flnm, 0, -1) 'Get all bytes from filelngSize = len (strBuff) flgFound = 0strTarget = chr (255) & chr (216) & chr (255) flgFound = instr (strBuff, strTarget) if flgFound = 0 thenexit functionend ifstrImageType = "JPG" lngPos = flgFound 2ExitLoop = falsedo while ExitLoop = False and lngPos

Do WHILE ASC (MID (Strbuff, LNGPOS, 1)) = 255 and LNGPOS 195 thenlngMarkerSize = lngConvert2 (mid (strBuff, lngPos 1, 2)) lngPos = lngPos lngMarkerSize 1elseExitLoop = Trueend ifloop'if ExitLoop = False thenWidth = -1Height = -1Depth = -1elseHeight = lngConvert2 (mid (strBuff, lngPos 4 , 2)) Width = LNGCONVERT2 (MID (Strbuff, LNGPOS 6, 2)) Depth = 2 ^ (ASC (MID (Strbuff, LNGPOS 8, 1)) * 8) GFXSPEX = TrueEnd IFEND Function

': :::::::::::::::::::::::::: :::::::::::::::::::::::::::::::: :::::: :::::::::::::::::: "For for Test, we put the file in C: / on set objfso = createObject ("scripting.filesystemObject") set objf = objfso.getfolder ("c: /") set objfc = objf.filesResponse.write "

"for Each F1 in Objfcif Instr (ucase (f1.name)," .gif ") ThenResponse.write"
"& f1.name &" "& f1.datecreated &" "& f1.size &" "IF GFXSPEX (f1.path, w, h, c, strtype) = True ThenRESPONSE.WRITE W & "X" & H & "" Elseresponse.write "" end ifresponse.write " " end ifnextResponse.write "" SET Objfc = NothingSet Objf = NothingSet Objfso = Nothing%>

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

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.046, SQL: 9