#!/usr/bin/env python3 """Rasterize locked prototype rating marks at the Coming-in row's native pixel size.""" from pathlib import Path from io import BytesIO import hashlib import json import cairosvg from PIL import Image, ImageOps ROOT = Path(__file__).resolve().parent SOURCE = ROOT / "request-marks" OUTPUT = ROOT / "src/main/res/drawable-nodpi" def main() -> None: """Keep the original SVGs and record hashes alongside generated television-size PNGs.""" OUTPUT.mkdir(parents=True, exist_ok=True) tokens = json.loads((ROOT / "tokens.json").read_text()) supplement = json.loads((ROOT / "shell-tokens.json").read_text()) height = int(tokens["type"]["label"]["px"]) wordmark_ratio = supplement["requests"]["ratingsWordmarkRatio"]["$value"] manifest = [] for source in sorted(SOURCE.glob("*.svg")): target = OUTPUT / f"coming_in_rating_{source.stem}.png" width = round(height * wordmark_ratio) if source.stem in ("imdb", "tmdb") else height source_pixels = cairosvg.svg2png(url=str(source), output_height=height * 4) with Image.open(BytesIO(source_pixels)) as image: ImageOps.fit(image, (width, height), method=Image.Resampling.LANCZOS).save(target) for path in (source, target): manifest.append(f"{hashlib.sha256(path.read_bytes()).hexdigest()} {path.relative_to(ROOT)}") (ROOT / "request-marks.sha256").write_text("\n".join(manifest) + "\n") if __name__ == "__main__": main()