"""Frames raw device captures into Play-ready store screenshots. Play accepts phone screenshots with an aspect ratio up to 2:1. The Redmi Note 10 captures are 1080x2400 (9:20 = 2.22:1) and would be rejected, so each shot is scaled down and composited onto a 1080x1920 brand canvas: 16:9, no cropping of the UI, and the frame gives the store page a consistent look. python3 tools/art/gen_screens.py Raw captures live in store/screenshots/raw/, the framed results replace store/screenshots/01..04. Re-capture the raw shots after any visible change: adb exec-out screencap -p > store/screenshots/raw/01_aiming.png """ from __future__ import annotations import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) from PIL import Image, ImageDraw, ImageFilter import artlib as A P = A.Palette.load() SCREENS = A.ROOT / "store" / "screenshots" RAW = SCREENS / "raw" CANVAS = (1080, 1920) SHOT_HEIGHT = 1660 # leaves 130 px breathing room top and bottom CORNER = 34 def _background() -> Image.Image: """Vertical ink gradient with a warm glow behind the phone, plus vignette.""" w, h = CANVAS img = Image.new("RGB", CANVAS, P.color("ink.0")) draw = ImageDraw.Draw(img) top = (5, 7, 10) mid = (16, 27, 41) bottom = (8, 10, 14) for y in range(h): t = y / (h - 1) if t < 0.55: k = t / 0.55 color = tuple(int(top[i] + (mid[i] - top[i]) * k) for i in range(3)) else: k = (t - 0.55) / 0.45 color = tuple(int(mid[i] + (bottom[i] - mid[i]) * k) for i in range(3)) draw.line([(0, y), (w, y)], fill=color) glow = Image.new("RGB", CANVAS, (0, 0, 0)) gd = ImageDraw.Draw(glow) gd.ellipse([w * 0.05, h * 0.18, w * 0.95, h * 0.82], fill=(90, 52, 20)) glow = glow.filter(ImageFilter.GaussianBlur(180)) return Image.blend(img, Image.blend(img, glow, 0.35), 0.55) def _rounded(img: Image.Image, radius: int) -> Image.Image: mask = Image.new("L", img.size, 0) ImageDraw.Draw(mask).rounded_rectangle([0, 0, img.size[0] - 1, img.size[1] - 1], radius=radius, fill=255) out = img.convert("RGBA") out.putalpha(mask) return out def frame(raw: Path, out: Path) -> Path: shot = Image.open(raw).convert("RGB") scale = SHOT_HEIGHT / shot.height shot = shot.resize((int(shot.width * scale), SHOT_HEIGHT), Image.LANCZOS) shot = _rounded(shot, CORNER) canvas = _background().convert("RGBA") x = (CANVAS[0] - shot.width) // 2 y = (CANVAS[1] - SHOT_HEIGHT) // 2 shadow = Image.new("RGBA", CANVAS, (0, 0, 0, 0)) ImageDraw.Draw(shadow).rounded_rectangle( [x + 10, y + 26, x + shot.width + 10, y + SHOT_HEIGHT + 26], radius=CORNER, fill=(0, 0, 0, 150)) shadow = shadow.filter(ImageFilter.GaussianBlur(28)) canvas = Image.alpha_composite(canvas, shadow) # Hairline edge so the frame reads as a device, not a pasted image. edge = Image.new("RGBA", CANVAS, (0, 0, 0, 0)) ImageDraw.Draw(edge).rounded_rectangle( [x - 1, y - 1, x + shot.width, y + SHOT_HEIGHT], radius=CORNER + 1, outline=(255, 255, 255, 40), width=2) canvas = Image.alpha_composite(canvas, edge) canvas.paste(shot, (x, y), shot) out.parent.mkdir(parents=True, exist_ok=True) canvas.convert("RGB").save(out, optimize=True) return out def main() -> int: raws = sorted(RAW.glob("*.png")) if not raws: print(f"no raw captures in {RAW} - run the adb captures first", file=sys.stderr) return 1 for raw in raws: target = SCREENS / raw.name frame(raw, target) print(f" {target.relative_to(A.ROOT)} {Image.open(target).size}") return 0 if __name__ == "__main__": raise SystemExit(main())