"""Generate the openhop brand: app icon (.ico, multi-size), PNGs and SVGs. Logo = "Tag": a stencil lowercase 'h' (the arch has hopped off the stem) on an amber equipment tag with chamfered corners. Chosen by the user on 2026-11-15 (see assets/brand/options/option3-tag.png). Usage: python tools/make_brand.py Writes src/assets/openhop.ico, assets/brand/*.png|svg and assets/brand/_preview.png (review only, not committed). """ import pathlib import sys from PIL import Image, ImageDraw ROOT = pathlib.Path(sys.argv[1]) if len(sys.argv) > 1 else pathlib.Path(__file__).resolve().parent.parent BRAND = ROOT / "assets" / "brand" BRAND.mkdir(parents=True, exist_ok=True) # Brand colours (also used by the UI: --brand / --ink / --paper) AMBER = "#f2b318" GRAPHITE = "#1f2125" PAPER = "#efede6" def _rgb(h): return tuple(int(h[i:i + 2], 16) for i in (1, 3, 5)) def plate_pts(inset, chamfer): a, b, c = inset, 100 - inset, chamfer return [(a + c, a), (b - c, a), (b, a + c), (b, b - c), (b - c, b), (a + c, b), (a, b - c), (a, a + c)] def plate_path(inset, chamfer): p = plate_pts(inset, chamfer) return "M" + " L".join(f"{x:g} {y:g}" for x, y in p) + " Z" # Geometry in a 100x100 box. Small sizes drop the rim + hang hole and use a tighter plate. DETAIL = dict(inset=3, chamfer=9) SMALL = dict(inset=1, chamfer=7) STEM = (22, 17, 37, 83) # x0, y0, x1, y1 ARCH_W = 15 # stroke width of the shoulder # centre-line of the shoulder: M41 41.5 H51 Q68.5 41.5 68.5 59 V83 (butt ends) def arch_centerline(steps=600): pts = [(41 + (51 - 41) * i / 60, 41.5) for i in range(61)] for i in range(steps + 1): t = i / steps u = 1 - t pts.append((u * u * 51 + 2 * u * t * 68.5 + t * t * 68.5, u * u * 41.5 + 2 * u * t * 41.5 + t * t * 59)) pts += [(68.5, 59 + (83 - 59) * i / 60) for i in range(61)] return pts ARCH = arch_centerline() def render(px: int) -> Image.Image: detail = px > 32 ss = 8 if px <= 64 else 4 S = px * ss k = S / 100.0 img = Image.new("RGBA", (S, S), (0, 0, 0, 0)) d = ImageDraw.Draw(img) geo = DETAIL if detail else SMALL d.polygon([(x * k, y * k) for x, y in plate_pts(**geo)], fill=_rgb(AMBER)) ink = _rgb(GRAPHITE) if detail: rim = Image.new("L", (S, S), 0) ImageDraw.Draw(rim).polygon([(x * k, y * k) for x, y in plate_pts(7, 7)], outline=255, width=max(1, round(1.4 * k))) img.paste(ink + (46,), (0, 0), rim.point(lambda v: v * 46 // 255)) hole = Image.new("L", (S, S), 0) hr, hw = 4.2 * k, 2 * k ImageDraw.Draw(hole).ellipse((84 * k - hr - hw / 2, 16 * k - hr - hw / 2, 84 * k + hr + hw / 2, 16 * k + hr + hw / 2), fill=255) ImageDraw.Draw(hole).ellipse((84 * k - hr + hw / 2, 16 * k - hr + hw / 2, 84 * k + hr - hw / 2, 16 * k + hr - hw / 2), fill=0) img.paste(ink, (0, 0), hole.point(lambda v: v * 115 // 255)) x0, y0, x1, y1 = STEM d.rectangle((x0 * k, y0 * k, x1 * k, y1 * k), fill=ink) # shoulder: stamp round dabs along the centre-line, then cut butt ends (x<41, y>83) arch = Image.new("L", (S, S), 0) ad = ImageDraw.Draw(arch) r = ARCH_W / 2 * k for x, y in ARCH: ad.ellipse((x * k - r, y * k - r, x * k + r, y * k + r), fill=255) ad.rectangle((0, 0, 41 * k, S), fill=0) ad.rectangle((0, 83 * k, S, S), fill=0) img.paste(ink, (0, 0), arch) return img.resize((px, px), Image.LANCZOS) GLYPH_SVG = (f'' f'') def icon_svg(detail=True): geo = DETAIL if detail else SMALL extra = (f'' f'' if detail else "") return (f'' f'{extra}{GLYPH_SVG}\n') def main(): sizes = [16, 24, 32, 48, 64, 128, 256] frames = {s: render(s) for s in sizes} (ROOT / "src" / "assets").mkdir(parents=True, exist_ok=True) frames[256].save(ROOT / "src" / "assets" / "openhop.ico", format="ICO", sizes=[(s, s) for s in sizes], append_images=[frames[s] for s in sizes if s != 256]) for s in (1024, 512, 256): render(s).save(BRAND / f"openhop-icon-{s}.png") (BRAND / "openhop-icon.svg").write_text(icon_svg(True), encoding="utf-8") (BRAND / "openhop-icon-small.svg").write_text(icon_svg(False), encoding="utf-8") (BRAND / "openhop-mark.svg").write_text( f'{GLYPH_SVG}\n', encoding="utf-8") for name, word in (("openhop-wordmark.svg", GRAPHITE), ("openhop-wordmark-dark.svg", PAPER)): (BRAND / name).write_text( '' + icon_svg(True).replace('', '') + f'' 'openhop\n', encoding="utf-8") # review sheet W = 40 + sum(s + 28 for s in sizes) sheet = Image.new("RGBA", (W, 600), (17, 18, 20, 255)) sheet.paste(Image.new("RGBA", (W, 300), _rgb(PAPER) + (255,)), (0, 300)) x = 20 for s in sizes: for row in (0, 300): sheet.alpha_composite(frames[s], (x, row + 150 - s // 2)) x += s + 28 sheet.save(BRAND / "_preview.png") print("ok", sorted(p.name for p in BRAND.iterdir() if p.is_file())) if __name__ == "__main__": main()