Use FSO to get information on image files (size, wide, high)

xiaoxiao2021-03-06  199

<%

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

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

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

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

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

'' ::: ::::

'' ::: this function gets a specified number of bytes from any :::

'' ::: File, Starting At the Offset (Base 1) :::

'' ::: ::::

'' :::Pased: :::

'' ::: flnm => filespec of file to read :::

'' ::: Offset => Offset at Which to Start Reading :::

'' ::: Bytes => How much bytes to read :::

'' ::: ::::

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

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 the filesizeSet ​​objFTemp = objFSO.GetFile (flnm) lngSize = objFTemp.Sizeset objFTemp = nothingfsoForReading = 1Set objTextStream = objFSO.OpenTextFile (flnm, fsoForReading) if offset> 0 thenstrBuff = objTextStream.Read (offset - 1) end ifif bytes = -1 then '' Get All! GetBytes = objTextStream.Read (lngSize) '' ReadAllelseGetBytes = objTextStream.Read (bytes) end ifobjTextStream.Closeset objTextStream = nothingset objFSO = nothingend function '' ::::::: ::::: :::::::::::::::::::::: ::::: ::: '' ::: Functions to Convert Two bytes to a Numeric Value (long) ::: '::: (Both Little-endian and big -endian) ::: '' :::::::::: :::::::::::::::: :::::::::::::::: ) (ASC (Right (strTemp, 1)) * 256)))))) End FunctionFunction LNGCONVERT2 (STRTEMP) LNGCONVERT2 = CLNG (ASC (Right (strTemp, 1)) ((ASC (Lef T (strTemp, 1)) * 256))) End Function

'' ::: :::::::::::::::::::::: :::::::::: '' ::: ::: '' ::: this function does Most of the real work. It will attempt ::: '': : ::: '::: :::' ::: Pass ::: ':: Pass :::' ::: passed: ::: i : '' ::: flnm => filespec of file to read ::: '::: width => width of image :::' ::: height => 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 kil1n '' is gifstrimageTyp E = "GIF" width = LNGCONVERT (Gettes (FLNM, 7, 2)) Height = LNGCONVERT (GetBytes (FLNM, 9, 2)) DEPTH = 2 ^ ((ASC (Gettes (FLNM, 11, 1)) and 7 ) 1) gfxspex = trueelseif left (strbmp dam "'is bmpstrimageType =" bmp "width = LNGCONVERT (GetBytes (FLNM, 19, 2)) HEIGHT = LNGCONVERT (Getbytes (FLNM, 23, 2)) Depth = 2 ^ (ASC (GetBytes (FLNM, 29, 1))) GFXSPEX = Trueelseif Strtype = Strpng Then ''

IS pngstrimagetype = "png" width = LNGCONVERT2 (Gettes (FLNM, 19, 2)) Height = LNGCONVERT2 (GetBytes (FLNM, 23, 2)) DEPTH = GetBytes (FLNM, 25, 2) SELECT CASE ASC (Right (DEPTH, 1)) Case 0Depth = 2 ^ (ASC (defrm (depth, 1))) GFXSPEX = truecase 2Depth = 2 ^ (ASC (DEPTH, 1)) * 3) GFXSPEX = truecase 3Depth = 2 ^ (ASC (Left (Depth, 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 IF

End ifend function

'' ::: :::::::::::::::::::::: ::::::: test harness ::: '' :::::::::::::: ::::: :::::::::::::::::::::: ::

'' To test, We ''ll Just Try to show all files with a .gif extension in the root of c: 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 &" " GFXSPEX (F1.Path, W, H, C, Strtype) = True ThenResponse.write W & "& H &" & C & "Colors" Elseresponse.write "" End ifresponse.write " < / TR> "end ifnextresponse.write" "set objfc = nothingset objf = NothingSet objfso = Nothing

%>

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

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