import sys, struct from collections import namedtuple
if len(sys.argv) < 2: exit()
BitmapInfo = namedtuple('BitmapInfo', ['sign', 'size', 'save', 'offset', 'header_bytes', 'width', 'height', 'const', 'ncolor'])
with open(sys.argv[1], 'rb') as f: content = f.read(30) bmpinfo = BitmapInfo(*struct.unpack('<2sIIIIIIHH', content))
print(bmpinfo)
Sign in to make a reply
浅色太阳镜后的眼睛
!/usr/bin/env python
Filename: bmpinfo.py
Tell if a file is a bitmap, if so, print its info.
import sys, struct from collections import namedtuple
if len(sys.argv) < 2: exit()
BitmapInfo = namedtuple('BitmapInfo', ['sign', 'size', 'save', 'offset', 'header_bytes', 'width', 'height', 'const', 'ncolor'])
with open(sys.argv[1], 'rb') as f: content = f.read(30) bmpinfo = BitmapInfo(*struct.unpack('<2sIIIIIIHH', content))
print(bmpinfo)