def createEmptyImage(file, width, height):
w = width
h = height
filesize = 54 + 3 * width * height
img = [0 for i in range(3 * w * h)]
header = [66, 77, 0, 0, 0, 0, 0, 0, 0, 0, 54, 0, 0, 0, 40, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 24, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
header[2] = filesize % 256
header[3] = (filesize >> 8) % 256
header[4] = (filesize >> 16) % 256
header[5] = (filesize >> 24) % 256
header[18] = (width) % 256
header[19] = (width >> 8) % 256
header[20] = (width >> 16) % 256
header[21] = (width >> 24) % 256
header[22] = (height) % 256
header[23] = (height >> 8) % 256
header[24] = (height >> 16) % 256
header[25] = (height >> 24) % 256
f = open(file, "wb")
f.write(bytes(header))
for i in range(height):
f.write(bytes(img[(width * (h - i - 1) * 3):(width * (h - i - 1) * 3) + 3 * width]))
f.write(bytes([0, 0, 0][:(4 - (width * 3) % 4) % 4]))
f.close()
Не самое короткое решение, но оно отлично работает