def checkBmpFile(filePath):
with open(filePath, 'rb') as f:
s = f.read(30)
info = struct.unpack('<ccIIIIIIHH', s)
print(info)
if(info[0] == b'B' and info[1] == b'M'):
print('This image file is a bmp file with width %d, height %d and colors %d' %(info[6], info[7],info[9]))
return True
return False
if name == 'main':
checkBmpFile('C:\Program Files\Microsoft Office\CLIPART\PUB60COR\J0101856.BMP')
lubang03
import struct
def checkBmpFile(filePath): with open(filePath, 'rb') as f: s = f.read(30) info = struct.unpack('<ccIIIIIIHH', s) print(info) if(info[0] == b'B' and info[1] == b'M'): print('This image file is a bmp file with width %d, height %d and colors %d' %(info[6], info[7],info[9])) return True return False
if name == 'main': checkBmpFile('C:\Program Files\Microsoft Office\CLIPART\PUB60COR\J0101856.BMP')