#!/usr/bin/env python3 # Builds the web UI's logo from the master image, artwork/logo.png (a blue # and white figure on a transparent background), by tracing it into vector # paths with potrace: # # internal/web/static/assets/logo.svg the favicon # internal/web/static/assets/logo.js the same paths for the web UI, which # draws them inline (brand.js), so the # logo appears together with the page # # and then runs scripts/banner.py to rebuild the README's banner. # # Both are a few KB, where the PNG is 650 KB. Needs potrace and ImageMagick # (convert). Run from the repository root after changing the master: # # python3 scripts/logo.py import os import re import subprocess import sys import tempfile MASTER = "artwork/logo.png" OUT = "internal/web/static/assets" BLUE = "#1d5287" # the master's blue WHITE = "#fff" PAD = 6 # pixels of the master around the figure def run(*args): return subprocess.run(args, check=True, capture_output=True, text=True).stdout def trace(pbm): """Traces a bitmap into one SVG path (in the master's pixels, y up).""" svg = run("potrace", "-b", "svg", "--flat", "-t", "4", "-a", "1.0", "-O", "0.4", "-u", "1", pbm, "-o", "-") return " ".join(re.search(r'' for fill, d in layers) with open(os.path.join(OUT, "logo.svg"), "w") as f: f.write(f'' f'' f'{paths}\n') with open(os.path.join(OUT, "logo.js"), "w") as f: f.write(f"// The Jarl logo, traced from {MASTER} by scripts/logo.py; don't edit.\n" f"// brand.js draws it; logo.svg holds the same paths.\n" f'export const viewBox = "{view_box}";\n' f'export const transform = "{transform}";\n' "export const layers = [\n" + "".join(f' ["{fill}", "{d}"],\n' for fill, d in layers) + "];\n") for name in ("logo.svg", "logo.js"): print(f"{OUT}/{name}: {os.path.getsize(os.path.join(OUT, name))} bytes", flush=True) subprocess.run([sys.executable, "scripts/banner.py"], check=True) if __name__ == "__main__": sys.exit(main())