from PIL import Image import sys import os if (len(sys.argv) < 2): print("Error: usage python icon_maker.py {img}") image = Image.open(sys.argv[1]) width, height = image.size pixels = list(image.getdata()) pixels = [r << 16 | g << 8 | b for r, g, b in pixels] string = str(pixels).replace("(", "{").replace(")", "}").replace("[", "{").replace("]", "}") filename: str = os.path.basename(sys.argv[1]).split(".")[0] string = f"""\ #pragma once #include #include "icon.h" uint32_t {filename}_color_map[{width} * {height}] = {string}; struct icon {filename}_icon = {{ .height = {height}, .width = {width}, .pixels = {filename}_color_map }}; """ if not os.path.exists("./headers/icons"): os.makedirs("./headers/icons") with open(f"./headers/icons/{filename}.h", "w") as f: f.write(string)