#!/usr/bin/env python SIZE = (84, 48) from PIL import Image print("/* Generated */") print() print("const char *frames[] = {{".format(SIZE[0] * SIZE[1])); for i in range(0, 7): path = "/home/matti/AndroidStudioProjects/SkullTrumpetProject/SkullTrumpet/src/main/res/drawable/spooky_skull_{0}.png".format(i) src = Image.open(path).convert("RGB") src.thumbnail((84, 48)) img = Image.new("RGB", SIZE) img.paste(src, (int(SIZE[0]/2 - src.size[0]/2), int(SIZE[1]/2 - src.size[1]/2))) #pal = Image.new("P", (1, 1)) #pal.putpalette([0, 0, 0, 1, 1, 1]) #img = img.quantize(palette=pal) #img.save("out_{0}.png".format(i)) data = img.getdata() print(" \"", end="") for y in range(0, SIZE[1], 8): for x in range(0, SIZE[0]): byte = 0x00 bit = 0x01 for ay in range(y, y + 8): color = data[ay * SIZE[0] + x] if color[0] > 25: byte |= bit bit <<= 1 print("\\x{0:02x}".format(byte), end=""); print("\",") print("};");