from PIL import Image im = Image.open('cursor.bmp') pixels = list(im.getdata()) w, h = im.size with open('gfxd_cursor.asm', 'w') as f: f.write(f'gfxd_cursor_dim: db {w} db {h}\n') f.write('gfxd_cursor: ') for px in pixels: if px == (255, 255, 255, 255): c = '0x0F' elif px == (0, 0, 0, 255): c = '0x00' else: c = '0xFF' f.write(f'db {c} ')