"""Site images from the shots (taken at 1280x960 by shots.sh; the crops below are in 640x480 units, scaled by K) (run from the repository root: python3 -I games/rob-revisited/tools/site/images.py)."""
import os
from PIL import Image

G = "games/rob-revisited"
K = 2  # shot size / 640
SRC = G + "/var/screenshots/s-%s.png"
OUT = G + "/site/images"
os.makedirs(OUT, exist_ok=True)
names = {"valley": "valley", "canyon": "canyon", "jungle": "jungle", "marsh": "marsh", "plateau": "plateau",
         "coast": "coast", "sunset": "sunset", "night": "night", "rain": "storm", "body": "body",
         "scanner": "scanner", "talk": "talk", "craft": "craft", "hands": "hands", "caves": "caves",
         "chest": "chest", "saves": "saves", "waterfall": "waterfall", "inventory": "inventory"}
for src, dst in names.items():
    im = Image.open(SRC % src).convert("RGB")
    im = im.resize((1280, round(im.height * 1280 / im.width)), Image.LANCZOS)
    im.save("%s/%s.jpg" % (OUT, dst), quality=85, optimize=True)

# the 3D view without the dashboard: the clear band between the top panels and the prompt
sun = Image.open(SRC % "sunset").convert("RGB")
og = sun.crop(tuple(v * K for v in (170, 66, 520, 250))).resize((1200, 630), Image.LANCZOS)
og.save(G + "/site/og.png", optimize=True)
th = sun.crop(tuple(v * K for v in (120, 40, 520, 265))).resize((640, 360), Image.LANCZOS)
th.save(G + "/assets/thumbnail.png", optimize=True)
sq = Image.open(SRC % "coast").convert("RGB").crop(tuple(v * K for v in (232, 78, 422, 268)))  # the shuttle
sq.resize((256, 256), Image.LANCZOS).save(G + "/assets/icon.png", optimize=True)
sq.resize((64, 64), Image.LANCZOS).save(OUT + "/favicon.png", optimize=True)

# hero banner: the sunset sky and land, no dashboard
sun.crop((0, 66 * K, 640 * K, 266 * K)).resize((1600, 500), Image.LANCZOS).save(OUT + "/hero.jpg", quality=85, optimize=True)
