#!/usr/bin/env python3 """ Regenerate docs/readme/main.svg, the consolidated SVG that drives README.md. The README is a single dark, on-brand image (hero + stats + CTAs + screenshot) that hands GitHub visitors off to https://alt-tab.app/. To stay seamless across GitHub light & dark themes, every visible element is baked into one SVG — including the hero screenshot, embedded as a base64 JPG. What this script does: 1. Reads a source screenshot (default: docs/readme/screenshot-source.webp). 2. Re-encodes it to a 1800-wide quality-86 JPG via ImageMagick. 3. Embeds it as base64 in the SVG template defined below. 4. Writes the result to docs/readme/main.svg. This script is intentionally NOT wired into CI. Run it manually after updating the source screenshot or the SVG layout. Stat values (downloads / GitHub stars) are NOT regenerated here — they live behind / markers in main.svg and are refreshed on every release by scripts/update_readme_and_website.sh. Usage: scripts/build_readme_svg.py [PATH_TO_SCREENSHOT] Without an argument, reads docs/readme/screenshot-source.webp. Pass a path to override (any format ImageMagick can read: webp, png, jpg). Requires: python3, ImageMagick (`magick`). """ import base64 import os import subprocess import sys import tempfile REPO_ROOT = os.path.normpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')) DEFAULT_SOURCE = os.path.join(REPO_ROOT, 'docs', 'readme', 'screenshot-source.webp') OUTPUT_PATH = os.path.join(REPO_ROOT, 'docs', 'readme', 'main.svg') def encode_screenshot(input_path: str) -> str: """Re-encode the source image to 1800-wide quality-86 JPG, return base64.""" with tempfile.NamedTemporaryFile(suffix='.jpg', delete=False) as tmp: tmp_path = tmp.name try: subprocess.run( ['magick', input_path, '-resize', '1800x>', '-quality', '86', tmp_path], check=True, ) with open(tmp_path, 'rb') as f: return base64.b64encode(f.read()).decode('ascii') finally: os.unlink(tmp_path) def build_svg(screenshot_b64: str) -> str: """ Build the SVG. Layout (y coordinates inside a 900x1040 viewBox): 50 - 194 : icon (144x144, vertically centered with the title+tagline stack) 120 : "AltTab Pro" title baseline 158 : tagline baseline 220 - 360 : stats container (deco 140x140 with number + label inside) 365 - 421 : CTA #1 455 - 916 : screenshot (820x461, rounded corners) 950 - 1006: CTA #2 Gradients (matching the website's _buttons.scss exactly): - Pro badge: 36deg, 60px period, animated 8s (one full horizontal period) - CTA pill : 36deg, 150px period, animated 14s (one full horizontal period) Stat values (7.4M, 15K) are placeholders — they sit behind XML comment markers (, ) so update_readme_and_website.sh can replace them via sed without re-running this script. """ return f''' AltTab Pro See every window. Switch in an instant. 7.4M DOWNLOADS 15K GITHUB STARS Get AltTab Get AltTab ''' def main() -> None: src = sys.argv[1] if len(sys.argv) > 1 else DEFAULT_SOURCE if not os.path.exists(src): print(f'error: screenshot not found at {src}', file=sys.stderr) print(f'pass a path as the first argument, or place the file at {DEFAULT_SOURCE}', file=sys.stderr) sys.exit(1) print(f'reading screenshot: {src}') b64 = encode_screenshot(src) svg = build_svg(b64) with open(OUTPUT_PATH, 'w') as f: f.write(svg) print(f'wrote {os.path.getsize(OUTPUT_PATH):,} bytes to {OUTPUT_PATH}') if __name__ == '__main__': main()