Voxley / app / Packaging / macOS / generate-background.py
| 1 | """Render original installer artwork at 1x/2x. Requires Pillow, not used in CI.""" |
| 2 | from pathlib import Path |
| 3 | import math |
| 4 | import subprocess |
| 5 | import tempfile |
| 6 | |
| 7 | from PIL import Image, ImageDraw, ImageFont |
| 8 | |
| 9 | ROOT = Path(__file__).resolve().parent |
| 10 | FONT = Path("/System/Library/Fonts/SFNS.ttf") |
| 11 | |
| 12 | |
| 13 | def draw_arrow(canvas: Image.Image, scale: int) -> None: |
| 14 | origin = (310, 204) |
| 15 | size = (100, 52) |
| 16 | samples = 4 * scale |
| 17 | mask = Image.new("L", tuple(edge * samples for edge in size)) |
| 18 | stroke = ImageDraw.Draw(mask) |
| 19 | left, tip = (324, 230), (396, 230) |
| 20 | upper, lower = (379, 213), (379, 247) |
| 21 | radius = 2 |
| 22 | |
| 23 | def point(coordinates: tuple[int, int]) -> tuple[int, int]: |
| 24 | x, y = coordinates |
| 25 | return ((x - origin[0]) * samples, (y - origin[1]) * samples) |
| 26 | |
| 27 | for path in ((left, tip), (upper, tip, lower)): |
| 28 | stroke.line([point(coordinates) for coordinates in path], |
| 29 | fill=255, width=2 * radius * samples, joint="curve") |
| 30 | for coordinates in (left, upper, tip, lower): |
| 31 | x, y = point(coordinates) |
| 32 | r = radius * samples |
| 33 | stroke.ellipse((x - r, y - r, x + r, y + r), fill=255) |
| 34 | |
| 35 | mask = mask.resize(tuple(edge * scale for edge in size), Image.Resampling.LANCZOS) |
| 36 | arrow = Image.new("RGB", mask.size, "#FFC977") |
| 37 | canvas.paste(arrow, tuple(edge * scale for edge in origin), mask) |
| 38 | |
| 39 | |
| 40 | def render(scale: int, target: Path) -> None: |
| 41 | width, height = 720 * scale, 460 * scale |
| 42 | canvas = Image.new("RGB", (width, height)) |
| 43 | pixels = canvas.load() |
| 44 | # A quiet navy field with light concentrated behind the installation path. |
| 45 | for y in range(height): |
| 46 | for x in range(width): |
| 47 | glow = math.exp(-(((x / scale - 360) / 410) ** 2 |
| 48 | + ((y / scale - 240) / 300) ** 2)) |
| 49 | pixels[x, y] = tuple(round(base + glow * lift) |
| 50 | for base, lift in zip((17, 20, 27), (17, 22, 32))) |
| 51 | draw = ImageDraw.Draw(canvas) |
| 52 | |
| 53 | def box(bounds): |
| 54 | return tuple(round(value * scale) for value in bounds) |
| 55 | |
| 56 | def text(value: str, y: int, size: int, color: str, weight: int = 400): |
| 57 | font = ImageFont.truetype(str(FONT), size * scale) |
| 58 | # SF's weight axis uses its own range. Select named instances when present. |
| 59 | names = font.get_variation_names() |
| 60 | desired = b"Bold" if weight >= 600 else b"Regular" |
| 61 | if desired in names: |
| 62 | font.set_variation_by_name(desired) |
| 63 | draw.text((360 * scale, y * scale), value, font=font, |
| 64 | fill=color, anchor="mt") |
| 65 | |
| 66 | draw.rounded_rectangle(box((18, 18, 702, 442)), radius=22 * scale, |
| 67 | outline="#4B4D53", width=scale) |
| 68 | text("Install Voxley", 48, 30, "#FFFFFF", 700) |
| 69 | text("Drag Voxley to Applications to get started.", 95, 16, "#E7DCC8") |
| 70 | |
| 71 | # The real draggable Finder icons are placed over these two quiet wells. |
| 72 | draw.rounded_rectangle(box((117, 154, 273, 316)), radius=22 * scale, |
| 73 | fill="#F4E2C6") |
| 74 | draw.rounded_rectangle(box((447, 154, 603, 316)), radius=22 * scale, |
| 75 | fill="#F4E2C6", outline="#D7AE73", width=scale) |
| 76 | # Rounded dotted outline: evenly spaced dots along four sides and corner arcs. |
| 77 | left, top, right, bottom, radius = 110, 147, 280, 323, 29 |
| 78 | dots = [] |
| 79 | for start, stop, fixed, horizontal in ( |
| 80 | (left + radius, right - radius, top, True), |
| 81 | (left + radius, right - radius, bottom, True), |
| 82 | (top + radius, bottom - radius, left, False), |
| 83 | (top + radius, bottom - radius, right, False), |
| 84 | ): |
| 85 | count = round((stop - start) / 9) |
| 86 | for index in range(count + 1): |
| 87 | value = start + (stop - start) * index / count |
| 88 | dots.append((value, fixed) if horizontal else (fixed, value)) |
| 89 | for cx, cy, begin in ((left + radius, top + radius, 180), |
| 90 | (right - radius, top + radius, 270), |
| 91 | (right - radius, bottom - radius, 0), |
| 92 | (left + radius, bottom - radius, 90)): |
| 93 | for angle in range(begin + 15, begin + 90, 20): |
| 94 | dots.append((cx + radius * math.cos(math.radians(angle)), |
| 95 | cy + radius * math.sin(math.radians(angle)))) |
| 96 | for x, y in dots: |
| 97 | draw.ellipse(box((x - 1.15, y - 1.15, x + 1.15, y + 1.15)), fill="#FFD792") |
| 98 | |
| 99 | draw_arrow(canvas, scale) |
| 100 | draw.line(box((88, 355, 632, 355)), fill="#4B4D53", width=scale) |
| 101 | text("Eject this disk image when copying is complete.", 378, 15, "#F6F3EB") |
| 102 | text("Open Voxley from your Applications folder.", 410, 14, "#BBC2CE") |
| 103 | canvas.save(target, dpi=(72 * scale, 72 * scale)) |
| 104 | |
| 105 | |
| 106 | if __name__ == "__main__": |
| 107 | with tempfile.TemporaryDirectory(prefix="voxley-dmg-artwork-") as directory: |
| 108 | normal = Path(directory) / "background.png" |
| 109 | retina = Path(directory) / "background@2x.png" |
| 110 | render(1, normal) |
| 111 | render(2, retina) |
| 112 | subprocess.run(["tiffutil", "-cathidpicheck", normal, retina, "-out", |
| 113 | ROOT / "background.tiff"], check=True) |