I need to read the header of a bmp file with python. I tried like this but it obviously returns just a bunch of non intelligible bytes:
f = open(input_filename,"rb")
data = bytearray(f.read())
f.close()
print(data[:14])
My idea was to find a module, or something fast, in order to log image info while opening it. I know about this function in matlab that does exactly what i want: imfinfo()
. But I can't find a counterpart in python.
To be clear, this is what I get with matlab:
FileModDate: '20-Oct-2017 09:42:24'
FileSize: 1311798
Format: 'bmp'
FormatVersion: 'Version 3 (Microsoft Windows 3.x)'
Width: 1280
Height: 1024
BitDepth: 8
ColorType: 'indexed'
FormatSignature: 'BM'
NumColormapEntries: 256
Colormap: [256x3 double]
RedMask: []
GreenMask: []
BlueMask: []
ImageDataOffset: 1078
BitmapHeaderSize: 40
NumPlanes: 1
CompressionType: 'none'
BitmapSize: 1310720
HorzResolution: 0
VertResolution: 0
NumColorsUsed: 256
NumImportantColors: 0
PIL
'sImage.info
? effbot.org/imagingbook/image.htm#tag-Image.Image.info – Nunnery{'dpi': (0, 0), 'compression': 0}
– Fineablestruct
module. docs.python.org/3/library/struct.html#module-struct – Tellurize