Files
sfhorizont/store/make_play_graphics.py
T

84 lines
4.3 KiB
Python
Raw Normal View History

2026-10-27 21:21:33 +01:00
"""Google Play graphics: 512×512 icon and a 1024×500 feature graphic per locale.
python3 store/make_play_graphics.py <work>
Needs <work>/profile.json from store/scene.py (the demo horizon drawn along the
bottom). Writes <work>/play-icon.png and <work>/<locale>/play/feature.png.
"""
import json
import subprocess
import sys
from pathlib import Path
HERE = Path(__file__).resolve().parent
ROOT = HERE.parent
CHROME = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
FONTS = (ROOT / 'wasm/frontend/node_modules/@fontsource/barlow/files').as_uri()
ICON = ROOT / 'assets/branding/icon-1024.png'
W, H = 1024, 500
def horizon_path(profile):
"""Profile (360 altitudes, degrees) → SVG area path along the bottom third."""
base, gain = H, 6.0 # 1° altitude → 6 px
pts = [(i * W / 359, base - 70 - alt * gain) for i, alt in enumerate(profile)]
line = ' '.join(f'{x:.1f},{y:.1f}' for x, y in pts)
return f'M0,{base} L{line} L{W},{base} Z', f'M{line.replace(" ", " L")}'
def html(subtitle, rtl, profile):
area, line = horizon_path(profile)
return f'''<!doctype html><html dir="{'rtl' if rtl else 'ltr'}"><head><meta charset="utf-8"><style>
@font-face {{ font-family: Barlow; font-weight: 700; src: url('{FONTS}/barlow-latin-700-normal.woff2'); }}
@font-face {{ font-family: Barlow; font-weight: 600; src: url('{FONTS}/barlow-latin-600-normal.woff2'); }}
@font-face {{ font-family: Barlow; font-weight: 600; src: url('{FONTS}/barlow-latin-ext-600-normal.woff2'); unicode-range: U+0100-024F; }}
html, body {{ margin: 0; width: {W}px; height: {H}px; overflow: hidden; }}
body {{ background: radial-gradient(110% 120% at 75% 0%, #1B2B4A 0%, #0B1222 50%, #04060B 100%); font-family: Barlow, 'Geeza Pro', system-ui, sans-serif; }}
.stars {{ position: absolute; inset: 0; background-image:
radial-gradient(1.5px 1.5px at 620px 60px, #fff9, transparent), radial-gradient(2px 2px at 900px 120px, #fffa, transparent),
radial-gradient(1.2px 1.2px at 760px 200px, #fff7, transparent), radial-gradient(1.5px 1.5px at 980px 40px, #fff8, transparent),
radial-gradient(1.2px 1.2px at 540px 170px, #fff6, transparent), radial-gradient(2px 2px at 840px 260px, #FFE9C7bb, transparent),
radial-gradient(1.2px 1.2px at 120px 40px, #fff6, transparent), radial-gradient(1.5px 1.5px at 450px 80px, #fff7, transparent); }}
.brand {{ position: absolute; top: 70px; inset-inline-start: 72px; display: flex; align-items: center; gap: 28px; }}
.brand img {{ width: 132px; height: 132px; border-radius: 30px; box-shadow: 0 16px 40px #0009; }}
h1 {{ margin: 0; color: #E8ECF2; font-weight: 700; font-size: 76px; line-height: 1; letter-spacing: -0.01em; direction: ltr; }}
p {{ margin: 12px 0 0; color: #F5B544; font-weight: 600; font-size: 34px; }}
svg {{ position: absolute; left: 0; bottom: 0; }}
</style></head><body><div class="stars"></div>
<div class="brand"><img src="{ICON.as_uri()}"><div><h1>SkyContour</h1><p>{subtitle}</p></div></div>
<svg width="{W}" height="{H}" viewBox="0 0 {W} {H}">
<path d="{area}" fill="#070A12"/>
<path d="{line}" fill="none" stroke="#F5B544" stroke-width="3" stroke-dasharray="10 7" stroke-linejoin="round"/>
</svg></body></html>'''
def render(src, png, w, h):
for _ in range(3): # headless Chrome occasionally exits non-zero
r = subprocess.run([CHROME, '--headless=new', '--hide-scrollbars', '--allow-file-access-from-files',
'--force-device-scale-factor=1', f'--window-size={w},{h}', f'--screenshot={png}',
src.as_uri()], capture_output=True)
if r.returncode == 0:
return
raise RuntimeError(f'render failed: {png}')
def main():
work = Path(sys.argv[1])
meta = json.loads((HERE / 'metadata.json').read_text())
profile = json.loads((work / 'profile.json').read_text())
subprocess.run(['sips', '-z', '512', '512', str(ICON), '--out', str(work / 'play-icon.png')],
check=True, capture_output=True)
for locale, m in meta.items():
if locale.startswith('_'):
continue
out = work / locale / 'play'
out.mkdir(parents=True, exist_ok=True)
page = out / 'feature.html'
page.write_text(html(m['subtitle'], m['app'] == 'ar', profile))
render(page, out / 'feature.png', W, H)
print(locale, 'ok')
if __name__ == '__main__':
main()