def filter_jpeg filename open filename rb read close if xff xc0 in ret

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
>>> def filter_jpeg(filename):
f=open(filename, 'rb')
d = f.read()
f.close()
if '\xff\xc0' in d: return 'Baseline'
if '\xff\xc2' in d: return 'Progressive'
>>> filter_jpeg('c:\\temp\\1.jpg')
'Baseline'
>>> filter_jpeg('c:\\temp\\2.jpg')
'Progressive'