import struct
def isBMP(f):
with open(f,'rb') as f:
test = f.read()
test = test[:30]
test = struct.unpack('<ccIIIIIIHH', test)
if test[0]==b'B' and test[1]==b'M':
print('pic size: %d*%d'%(test[6],test[7]))
print('color: %d'%(test[-1]))
else:
print('file not BMP')
f = '/Users/Jason/Desktop/test.bmp'
f2 = '/Users/Jason/Desktop/re.py'
isBMP(f)
isBMP(f2)
靠谱灬男青年