So in a bitmap image, according to Wikipedia, the width and height are stored at offsets 18 and 22, respectively, as signed integers.
Once you have your bitmap file open, you need to turn it into an array of bytes which can be read via an offset later on.
with open("test.bmp", "rb") as f:
data = bytearray(f.read())
the struct
module in Python's standard lib can be used to grab data at an offset of a bytearray, so a quick way to grab your info could be something like:
import struct
with open("test.bmp", "rb") as f:
data = bytearray(f.read())
# '<' means "Little-Endian"
# 'i' means int. Check the "format" table on https://docs.python.org/3/library/struct.html
width = struct.unpack_from('<i', data, 18)
height = struct.unpack_from('<i', data, 22)
print("Width: {}, Height: {}".format(width, height))