"""Recognize image file formats based on their first few bytes."""
#-------------------------#
# Recognize image headers #
#-------------------------#
if type(file) == type(''):
#---------------------------------#
# Subroutines per image file type #
#---------------------------------#
"""GIF ('87 and '89 variants)"""
if h
[:6] in ('GIF87a', 'GIF89a'):
"""PBM (portable bitmap)"""
h
[0] == 'P' and h
[1] in '14' and h
[2] in ' \t\n\r':
"""PGM (portable graymap)"""
h
[0] == 'P' and h
[1] in '25' and h
[2] in ' \t\n\r':
"""PPM (portable pixmap)"""
h
[0] == 'P' and h
[1] in '36' and h
[2] in ' \t\n\r':
"""TIFF (can be in Motorola or Intel byte order)"""
if h
[:2] in ('MM', 'II'):
if h
[:4] == '\x59\xA6\x6A\x95':
"""X bitmap (X10 or X11)"""
"""JPEG data in JFIF format"""
if h
[:8] == "\211PNG\r\n\032\n":
if sys
.argv
[1:] and sys
.argv
[1] == '-r':
testall(sys
.argv
[1:], recursive
, 1)
testall(['.'], recursive
, 1)
except KeyboardInterrupt:
sys
.stderr
.write('\n[Interrupted]\n')
def testall(list, recursive
, toplevel
):
if os
.path
.isdir(filename
):
if recursive
or toplevel
:
names
= glob
.glob(os
.path
.join(filename
, '*'))
testall(names
, recursive
, 0)
print '*** directory (use -r) ***'
print '*** not found ***'