from PIL import Image

# ask for image
path = input("Enter image path: ").strip()

# load and shrink image
img = Image.open(path).convert("RGBA")
img = img.resize((32, 32), Image.NEAREST)

output_file = "a.mcfunction"

with open(output_file, "w") as f:
    pixels = img.load()

    # bottom-right -> top-left row-wise
    for y in range(31, -1, -1):        # bottom to top
        for x in range(31, -1, -1):    # right to left
            index = (31 - y) * 32 + (31 - x)
            r, g, b, a = pixels[x, y]

            # skip transparent pixels
            if a == 0:
                continue

            rf = f"{r/255:.6f}f"
            gf = f"{g/255:.6f}f"
            bf = f"{b/255:.6f}f"

            line = f'data modify entity @n[tag=picture_screen] item.components."minecraft:custom_model_data".colors[{index}] set value [{rf}, {gf}, {bf}]\n'
            f.write(line)

print(f"Commands written to {output_file}")