"""Contact sheet of generated vocabulary pictures: python tools/contact_sheet.py out.png [key ...] (no keys = all, 6 per row)."""
import os, sys
from PIL import Image, ImageDraw
SRC = "F:/Solutions/Thinkera/Thinkera/Yaseen-French2/02-Production/assets/Unit-Vocab/VOCAB/images/generated/"
out, keys = sys.argv[1], sys.argv[2:]
files = [k + ".png" for k in keys] if keys else sorted(f for f in os.listdir(SRC) if f.endswith(".png"))
files = [f for f in files if os.path.exists(SRC + f)]
W, cols = 220, 6
rows = (len(files) + cols - 1) // cols
sheet = Image.new("RGB", (W * cols, (W + 22) * max(rows, 1)), "white")
d = ImageDraw.Draw(sheet)
for i, f in enumerate(files):
    im = Image.open(SRC + f).convert("RGB").resize((W, W))
    x, y = (i % cols) * W, (i // cols) * (W + 22)
    sheet.paste(im, (x, y))
    d.text((x + 6, y + W + 4), f[:-4], fill="black")
sheet.save(out)
print(len(files), "pictures ->", out)
