5 f3 L+ }5 Z q- L: e) P
4 P% _2 O. S8 p% W- y7 e: S8 H o, j# _/ @6 `8 f: ]
<%% }9 U: t4 g: ^8 C% _" t
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::$ _! G7 i" K6 P }- G3 @# U' J
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::2 D a. {2 x* U; z! M) Y
'::: BMP, GIF, JPG and PNG :::: o& `7 G7 Z3 M" K' C2 t3 H* E
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
. e) z* i$ o3 O- b7 `7 J':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::! Y5 L- `% a6 y5 s
'::: :::! {, G" P' `) F& L
'::: This function gets a specified number of bytes from any :::
( T7 S8 D" d9 `6 e'::: file, starting at the offset (base 1) :::
! ?0 R: j' l8 s" j* x'::: :::5 ]( j, y5 g; @/ n* j: ^
'::: Passed: :::
; \5 N9 Y2 T9 K+ `9 T'::: flnm => Filespec of file to read :::
* Y$ }- A9 ]1 ~, R+ Q. ?'::: offset => Offset at which to start reading :::
S7 p! b8 b. p" g3 c% ]'::: bytes => How many bytes to read :::3 E _7 L" j+ f, @" s2 ?7 Y5 a
'::: :::1 V7 q: k i3 g) c, F3 A$ g I
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
9 ~' t$ a/ |; [8 @, C! n% h& n' E2 w! @function GetBytes(flnm, offset, bytes)! ?6 @& w9 s# s, D% U( L
Dim objFSO$ E5 l3 _4 Q0 q# U( w% K" Q0 |
Dim objFTemp
9 d, v" d! q* `* dDim objTextStream% m; a3 ]: U2 D% y
Dim lngSize; I9 @0 ]; F# D* u, ?) C1 r/ D M9 o
on error resume next
J: h1 U5 L5 K, _ ^9 r( VSet objFSO = CreateObject("Scripting.FileSystemObject")# T& {7 } R X. F$ ~
6 D5 P& X! z( W* V3 D5 q6 H z' E" W' First, we get the filesize
- {; _9 m0 H' s3 U5 ~Set objFTemp = objFSO.GetFile(flnm)
1 ~ G O1 C; H4 \( B: j0 |lngSize = objFTemp.Size/ K3 d! n. }0 Z9 w
set objFTemp = nothing
7 {* ^- l# i9 @% Q2 E MfsoForReading = 1
S) V. y3 W3 j- s# S5 H1 X9 cSet objTextStream = objFSO.OpenTextFile(flnm, fsoForReading)4 ]% G5 Q' T2 l6 [1 T
if offset > 0 then! N" Q5 z r1 `* W
strBuff = objTextStream.Read(offset - 1)
: i6 `' w+ R# c% A zend if5 G6 T9 l* X/ b+ S
if bytes = -1 then ' Get All!
! M+ L1 H/ ~7 aGetBytes = objTextStream.Read(lngSize) 'ReadAll
* R! m. R% X3 Y6 c/ _else( G# j2 z+ a- c2 P9 W4 a& y: S) V% b
GetBytes = objTextStream.Read(bytes)
; }9 ]9 I7 y J; p4 M- L1 J$ mend if
' T8 H d4 Q) j! ?) X5 _, CobjTextStream.Close
3 X+ h2 b: i2 B& X( Aset objTextStream = nothing L$ Y( }) |! x9 B3 ]
set objFSO = nothing% |5 V8 h% C" B5 p
end function ) t, E5 K% f* `% `
, ]- f8 b; {, @ ]2 j% h& K6 ?':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
6 k& L0 X" h# q'::: :::
* d2 [- W$ O7 a C& L'::: Functions to convert two bytes to a numeric value (long) ::: V* e* @. `& k1 }9 A
'::: (both little-endian and big-endian) :::
0 N0 d0 p) O1 _6 }9 W6 C'::: :::
# l b$ {, I. U$ B4 R7 }':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
" p/ [/ d" `6 @ i L% @function lngConvert(strTemp)0 B \7 d0 O0 I0 P6 V
lngConvert = clng(asc(left(strTemp, 1)) + ((asc(right(strTemp, 1)) * 256)))
; B2 [4 i) m2 T; W( S3 j V7 qend function
% T6 h1 v6 {, K; T9 c& ufunction lngConvert2(strTemp)
' M( D5 }; f6 D ?' ~# a0 OlngConvert2 = clng(asc(right(strTemp, 1)) + ((asc(left(strTemp, 1)) * 256)))
6 J: b# L' g, H8 C$ rend function# V% U& I/ |# p% I
, c8 t3 u6 w$ O4 J$ E2 T! N':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::4 I* y& v; N5 P# S1 A0 ^
'::: :::+ T7 Y3 F2 E7 V* R% l8 j
'::: This function does most of the real work. It will attempt :::+ ]; T9 I4 F# {+ }7 D1 Z+ l4 _
'::: to read any file, regardless of the extension, and will :::6 P: s# ?1 u9 U2 X+ ]! A
'::: identify if it is a graphical image. ::: r$ c) @4 T2 {* R9 t# q! V
'::: :::
/ W: @7 d# K' B5 Y1 W0 `'::: Passed: :::
3 X' C* T7 [" ^/ q'::: flnm => Filespec of file to read :::
v# K+ l/ o5 E'::: width => width of image :::8 _& r3 t! r& G0 A7 y
'::: height => height of image :::* Z. \6 O" g3 H5 N. |
'::: depth => color depth (in number of colors) :::
8 N1 B* ~" r8 F! ^% K/ K'::: strImageType=> type of image (e.g. GIF, BMP, etc.) :::
& v4 R7 k( x0 j! Q'::: :::
1 e1 w' s' m& b* Q& U, y# q':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: I, j3 H" }( q, |) o' R
function gfxSpex(flnm, width, height, depth, strImageType), y. p" M1 Y& ]# |$ x: N% e
dim strPNG $ E8 J @$ }9 b: S! R& Q: a
dim strGIF
5 i6 u9 l7 r3 I& R- jdim strBMP- b" k! h2 G& ?7 v3 X1 n
dim strType! Q/ C- i, i/ `1 N
strType = ""3 r) W S- |/ A1 l
strImageType = "(unknown)"
& |) H7 I( ~2 g3 G6 V0 }gfxSpex = False7 [7 H1 i! @1 E4 a, q
strPNG = chr(137) & chr(80) & chr(78)
: ?; v3 K$ _ b$ s% B1 a$ g: mstrGIF = "GIF"- T8 P* w8 j k1 ` o# f& `2 s
strBMP = chr(66) & chr(77)6 l- O1 o/ c, z% r* M
strType = GetBytes(flnm, 0, 3)4 H: R( u% d9 V" U% V$ i6 X6 A
if strType = strGIF then ' is GIF- V4 a. c2 }2 U
strImageType = "GIF"8 z1 X) X; F% k# _- i2 D
Width = lngConvert(GetBytes(flnm, 7, 2))' I% C, M1 ?' t) s6 X5 `! `
Height = lngConvert(GetBytes(flnm, 9, 2))
; n. ?5 p; A% I. UDepth = 2 ^ ((asc(GetBytes(flnm, 11, 1)) and 7) + 1)+ A! z z: G/ a- n- P
gfxSpex = True' @3 C; \! p4 h
elseif left(strType, 2) = strBMP then ' is BMP# r4 U x4 t: w) G* U: O# @
strImageType = "BMP"6 @% f, R& u- m: N
Width = lngConvert(GetBytes(flnm, 19, 2))% a/ D' G, D: `5 ]0 s1 _6 @2 K2 m
Height = lngConvert(GetBytes(flnm, 23, 2))
. R/ T- J2 c% S1 m2 w' L+ ?2 dDepth = 2 ^ (asc(GetBytes(flnm, 29, 1)))
1 }3 C! Z; E0 `1 s$ ygfxSpex = True) i, e, H( J e) f' O0 [) `0 P
elseif strType = strPNG then ' Is PNG
3 Y& z5 Q. O! c5 \$ g% PstrImageType = "PNG"! [* W8 E3 N1 {6 Y, z: w
Width = lngConvert2(GetBytes(flnm, 19, 2)) P3 O/ |9 H/ C7 |1 X
Height = lngConvert2(GetBytes(flnm, 23, 2))" r0 e9 I; t$ z2 C8 Q! Y' H
Depth = getBytes(flnm, 25, 2)! }5 X, y& X7 x7 e, E& J
select case asc(right(Depth,1)) S7 t/ r) u, t5 g/ X
case 0. A2 }( B) u* u% P# N
Depth = 2 ^ (asc(left(Depth, 1)))7 v& U, \$ \7 |( y* Q
gfxSpex = True
3 `. L. U* ?6 G! F% V: j1 t+ f9 gcase 2
" u# N# q( ~1 J$ ^Depth = 2 ^ (asc(left(Depth, 1)) * 3)
( L' F- B2 j- Y. R% j0 j* g% W$ ZgfxSpex = True/ [+ u$ U, ~* h4 ~: R h+ N
case 3 C! v7 f! P5 F+ `* X: Q) C1 }
Depth = 2 ^ (asc(left(Depth, 1))) '87 `) E6 k7 d, _5 H
gfxSpex = True9 K( K4 J& ?5 `# K& r* x l2 y9 F
case 42 N7 m# o5 ~' R7 l
Depth = 2 ^ (asc(left(Depth, 1)) * 2)5 }$ {5 j$ I# W3 r$ m/ [# G7 N! b
gfxSpex = True1 Y' b% J* Q, U. d6 H
case 6
$ t# A# q& H4 f4 U# @3 KDepth = 2 ^ (asc(left(Depth, 1)) * 4)& A$ ]4 ]3 O) R- p
gfxSpex = True3 Q% U) \! M* Q: ?1 K( n
case else* t; W& Q$ ?* z' {" l. A
Depth = -1
+ F( ], k8 g. y# P# I! a, T2 s' Xend select
& Z4 l- |2 }) C" x9 B* E
! Q5 z4 E! A; M) g7 i0 qelse+ z3 H& Z& c3 W; s4 g8 J4 k+ f
strBuff = GetBytes(flnm, 0, -1) ' Get all bytes from file- L4 | M: k0 N! U+ j
lngSize = len(strBuff)
) v/ t, |) D& P9 Z4 m& oflgFound = 0
( A- Q ]/ D$ O( Q. R" S7 J* ^) [3 fstrTarget = chr(255) & chr(216) & chr(255)
3 n7 H% V, [) R% q! v" bflgFound = instr(strBuff, strTarget)
4 p' T( U7 i& h8 f f7 [+ Sif flgFound = 0 then. |- [' q- H K; `/ K/ r
exit function
5 o) D: d9 A4 P% r) a* Bend if
9 \: e; B! H5 ~3 ostrImageType = "JPG"
7 ?1 \: i" K h9 }# X; z2 MlngPos = flgFound + 2
: K9 [. g& a2 x2 `) }$ p8 s3 yExitLoop = false! K# M: F5 h' M, }
do while ExitLoop = False and lngPos < lngSize
6 q% ]- i3 N j0 E3 z9 u/ I# n- V. D# \. z4 e
do while asc(mid(strBuff, lngPos, 1)) = 255 and lngPos < lngSize1 ^, {$ Z) |& f- F5 z- \6 F2 J
lngPos = lngPos + 1
& ]5 a9 j1 Z, |) g8 |' X# j/ w" Gloop
; y4 P. A0 N: Y4 H: D( R0 K0 |if asc(mid(strBuff, lngPos, 1)) < 192 or asc(mid(strBuff, lngPos, 1)) > 195 then
6 B$ W6 w" X$ E% \$ O( TlngMarkerSize = lngConvert2(mid(strBuff, lngPos + 1, 2))) w1 {" H% S, B
lngPos = lngPos + lngMarkerSize + 1
7 y7 M. Z0 c2 f/ _0 pelse
) F# T$ \3 ]9 O/ }7 YExitLoop = True- j3 D3 X7 {. ~+ N: `
end if
# x7 n' k% A2 R4 E2 ?loop9 U' w9 W' b* i y3 ~
'
& M0 @* ?% t/ z& ^7 c1 H& V- Cif ExitLoop = False then
7 ]$ p6 g% ^0 u C% ?# C( h& v8 VWidth = -1
/ r; z% R1 z5 X2 L7 CHeight = -1! P* i8 v, S9 X9 P
Depth = -1
3 [ w# ? X8 {5 `else0 j. E2 U7 S8 ]. j7 {2 i
Height = lngConvert2(mid(strBuff, lngPos + 4, 2))
5 T, A8 R! q: }6 e" ^+ SWidth = lngConvert2(mid(strBuff, lngPos + 6, 2))
0 R9 i: C/ { o: p& bDepth = 2 ^ (asc(mid(strBuff, lngPos + 8, 1)) * 8) r. Z+ R% {! L% e! R
gfxSpex = True
9 L3 l9 r7 S& o0 o+ J* _; x$ Rend if
d9 K* b m9 s8 r% w" W& f4 W$ f' x( G) {
end if4 f* u7 E: h6 Z, t$ J- p
end function2 o9 l' s8 B5 E+ K9 }
7 ^ q0 h2 T) `; M
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
" p M+ B% q. L3 |' ?# D m'::: Test Harness :::
) f3 O' g* A0 s/ x/ a':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1 L. J! k) g2 {! C* U4 D- r& D7 ~5 w5 n- Z
' To test, we'll just try to show all files with a .GIF extension in the root of C:
" q- q' o1 r9 L- w* p" H ySet objFSO = CreateObject("Scripting.FileSystemObject")
5 I: e9 X' X$ h. Z: cSet objF = objFSO.GetFolder("c:\")- v7 ~" X' d, ]- \" N: P$ E- H
Set objFC = objF.Files% y4 r) k x& M) e) j" H1 s8 ]
response.write "<table border=""0"" cellpadding=""5"">"6 R2 {- _) J1 B& h0 Z! t+ L
For Each f1 in objFC
4 {2 I) E/ e w1 `. a, Y( R. sif instr(ucase(f1.Name), ".GIF") then+ [" B% t0 j7 T) a
response.write "<tr><td>" & f1.name & "</td><td>" & f1.DateCreated & "</td><td>" & f1.Size & "</td><td>". e0 h$ m1 y2 v# o
if gfxSpex(f1.Path, w, h, c, strType) = true then' y6 Y7 [, i( M q/ t1 d4 e7 C
response.write w & " x " & h & " " & c & " colors"
S, w/ K, ? Eelse
8 M$ R0 l/ E; m$ T6 Dresponse.write " " f' h. n* p2 c" h
end if
+ D5 T0 i( l( u3 ^' T/ Yresponse.write "</td></tr>": j& S& B0 O: N! `# v+ M, U, t
end if
( K# v$ X( F( Z! cNext- Q. i" @3 X0 S, M9 h% u0 I; f+ m
response.write "</table>"" h n/ m) w0 Q' g7 U+ }9 H
set objFC = nothing
& H( p; v: x7 t% z3 C( ]; iset objF = nothing
4 H+ Q7 w% U: j5 \% G. X# gset objFSO = nothing
. h; d! V' S5 l; G2 c* b/ w" B3 g$ |! n8 S: b& s* c9 M
%>5 s3 H: H0 E& F" j1 O' Z6 m5 E) `
2 K, ]0 L9 V& Y) Z" f4 f |
|