146 lines
6.3 KiB
Python
146 lines
6.3 KiB
Python
#!/usr/bin/env python3
|
|
"""Builds the Google Play graphics from the raw emulator screenshots.
|
|
|
|
python3 store/make_graphics.py
|
|
|
|
Needs chromium and ImageMagick (magick). Reads store/screenshots/raw/*.png,
|
|
writes store/out/: phone screenshots (1080x1920), feature graphic (1024x500)
|
|
and the 512x512 icon. Edit SLIDES to change captions or order.
|
|
"""
|
|
import html
|
|
import pathlib
|
|
import subprocess
|
|
import tempfile
|
|
|
|
ROOT = pathlib.Path(__file__).resolve().parent
|
|
RAW = ROOT / "screenshots" / "raw"
|
|
OUT = ROOT / "out"
|
|
ICON = ROOT.parent / "assets" / "Icon.png"
|
|
ACCENT = "#00BCD4" # the app's default hit colour (Cian)
|
|
|
|
# (raw screenshot, headline, subline, blur everything above this y in px or None)
|
|
SLIDES = [
|
|
("03_knjiga_leto.png", "Spremljaj svoj napredek",
|
|
"Povprečje, rekordi in graf napredka", None),
|
|
("04_seja.png", "Vsi streli na eni tarči",
|
|
"Cel trening na enem pogledu", None),
|
|
("10_kamera_ziva.png", "Tarča v živo z IP kamero",
|
|
"Spremljaj zadetke na telefonu, brez hoje do tarče", None),
|
|
("11_kamera_telefon.png", "Fotografiraj tarčo",
|
|
"Poravnaj jo v kvadrat, zadetke prešteje aplikacija", None),
|
|
("08_po_meri.png", "Tarča po tvojem okusu",
|
|
"Izberi slog tarče in barvo zadetkov", None),
|
|
("07_tarca.png", "Več kot ducat tarč",
|
|
"Od klasične do plamenov in valov", None),
|
|
("05_tekmovanja.png", "Treningi in tekmovanja",
|
|
"Ločena statistika za vadbo in tekme", None),
|
|
("06_barva_zadetkov.png", "Zadetki v tvoji barvi",
|
|
"15 barv, da so zadetki vedno dobro vidni", 1596),
|
|
]
|
|
|
|
BASE_CSS = """
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
html, body { width: %(w)dpx; height: %(h)dpx; overflow: hidden; }
|
|
body {
|
|
font-family: 'Noto Sans', 'Liberation Sans', sans-serif;
|
|
color: #fff;
|
|
background:
|
|
radial-gradient(ellipse 80%% 50%% at 50%% 0%%, rgba(0,188,212,.28), transparent 70%%),
|
|
linear-gradient(180deg, #1d2427 0%%, #121416 100%%);
|
|
}
|
|
.phone {
|
|
border-radius: 64px; padding: 14px; background: #0b0b0c;
|
|
box-shadow: 0 0 0 3px #3a3f44, 0 40px 80px rgba(0,0,0,.55);
|
|
}
|
|
.phone img { display: block; border-radius: 52px; width: 100%%; }
|
|
"""
|
|
|
|
|
|
def chromium_png(page: str, w: int, h: int, out: pathlib.Path, tmp: pathlib.Path):
|
|
src = tmp / (out.stem + ".html")
|
|
src.write_text(page, encoding="utf-8")
|
|
subprocess.run(
|
|
["chromium", "--headless=new", "--disable-gpu", "--hide-scrollbars",
|
|
"--force-device-scale-factor=1", f"--window-size={w},{h}",
|
|
f"--screenshot={out}", "--default-background-color=00000000",
|
|
src.as_uri()],
|
|
check=True, capture_output=True)
|
|
# Play wants opaque PNG/JPEG
|
|
subprocess.run(["magick", str(out), "-background", "#121416", "-alpha",
|
|
"remove", "-alpha", "off", str(out)], check=True)
|
|
|
|
|
|
def prepared(name: str, blur_above, tmp: pathlib.Path) -> pathlib.Path:
|
|
"""The raw shot, optionally with everything above y blurred (hides the club section)."""
|
|
src = RAW / name
|
|
if blur_above is None:
|
|
return src
|
|
out = tmp / name
|
|
subprocess.run(
|
|
["magick", str(src), "(", "+clone", "-crop", f"1080x{blur_above}+0+0",
|
|
"+repage", "-blur", "0x28", ")", "-geometry", "+0+0", "-composite",
|
|
str(out)], check=True)
|
|
return out
|
|
|
|
|
|
def slide(img: pathlib.Path, title: str, sub: str) -> str:
|
|
css = BASE_CSS % {"w": 1080, "h": 1920} + f"""
|
|
.cap {{ text-align: center; padding: 100px 70px 0; }}
|
|
.cap h1 {{ font-size: 76px; font-weight: 800; line-height: 1.1; letter-spacing: -1px; }}
|
|
.cap h1::after {{ content: ''; display: block; width: 90px; height: 8px;
|
|
border-radius: 4px; background: {ACCENT}; margin: 34px auto 0; }}
|
|
.cap p {{ margin-top: 30px; font-size: 38px; line-height: 1.35; color: #c4ccd0; }}
|
|
.phone {{ position: absolute; left: 50%; top: 470px; width: 630px;
|
|
transform: translateX(-50%); }}
|
|
"""
|
|
return f"""<!doctype html><html><head><meta charset="utf-8"><style>{css}</style></head>
|
|
<body><div class="cap"><h1>{html.escape(title)}</h1><p>{html.escape(sub)}</p></div>
|
|
<div class="phone"><img src="{img.as_uri()}"></div></body></html>"""
|
|
|
|
|
|
def feature(img: pathlib.Path, icon: pathlib.Path) -> str:
|
|
css = BASE_CSS % {"w": 1024, "h": 500} + f"""
|
|
body {{ background:
|
|
radial-gradient(circle at 78% 55%, rgba(30,144,255,.35), transparent 55%),
|
|
radial-gradient(ellipse at 0% 0%, rgba(0,188,212,.25), transparent 60%),
|
|
linear-gradient(120deg, #1d2427, #101214); }}
|
|
.left {{ position: absolute; left: 64px; top: 0; bottom: 0; width: 560px;
|
|
display: flex; flex-direction: column; justify-content: center; }}
|
|
.logo {{ width: 96px; height: 96px; border-radius: 24px; background: #fff;
|
|
padding: 10px; margin-bottom: 26px; }}
|
|
.logo img {{ width: 100%; height: 100%; }}
|
|
h1 {{ font-size: 66px; font-weight: 800; letter-spacing: -1px; line-height: 1; }}
|
|
h1 span {{ color: {ACCENT}; }}
|
|
p {{ margin-top: 18px; font-size: 27px; line-height: 1.35; color: #c4ccd0; }}
|
|
.phone {{ position: absolute; right: 70px; top: 46px; width: 290px;
|
|
border-radius: 40px; padding: 8px; transform: rotate(6deg); }}
|
|
.phone img {{ border-radius: 32px; }}
|
|
"""
|
|
return f"""<!doctype html><html><head><meta charset="utf-8"><style>{css}</style></head>
|
|
<body><div class="left"><div class="logo"><img src="{icon.as_uri()}"></div>
|
|
<h1>SD <span>Kovinar</span></h1>
|
|
<p>Strelski dnevnik: rezultati, napredek in tarče po tvoji meri.</p></div>
|
|
<div class="phone"><img src="{img.as_uri()}"></div></body></html>"""
|
|
|
|
|
|
def main():
|
|
OUT.mkdir(exist_ok=True)
|
|
with tempfile.TemporaryDirectory() as t:
|
|
tmp = pathlib.Path(t)
|
|
for i, (name, title, sub, blur) in enumerate(SLIDES, 1):
|
|
img = prepared(name, blur, tmp)
|
|
out = OUT / f"phone_{i:02d}_{pathlib.Path(name).stem}.png"
|
|
chromium_png(slide(img, title, sub), 1080, 1920, out, tmp)
|
|
print("wrote", out.relative_to(ROOT.parent))
|
|
out = OUT / "feature_graphic.png"
|
|
chromium_png(feature(RAW / "09_val_modra.png", ICON), 1024, 500, out, tmp)
|
|
print("wrote", out.relative_to(ROOT.parent))
|
|
icon = OUT / "icon_512.png"
|
|
subprocess.run(["magick", str(ICON), "-resize", "512x512", "-background",
|
|
"white", "-alpha", "remove", "-alpha", "off", str(icon)], check=True)
|
|
print("wrote", icon.relative_to(ROOT.parent))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|