| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- """Generate committed Android launcher and splash assets from the PC MDIOP mark."""
- from __future__ import annotations
- from pathlib import Path
- from PIL import Image, ImageDraw
- ROOT = Path(__file__).resolve().parents[2]
- OUTPUT_DIR = ROOT / "App" / "src" / "static" / "branding" / "android"
- WEB_ICON = ROOT / "Web" / "public" / "app-icons" / "mdiop-app.png"
- ICON_SIZES = (48, 72, 96, 144, 192, 512, 1024)
- def render_mdiop_icon(size: int = 1024) -> Image.Image:
- """Rasterize the geometry from Web/public/app-icons/brand-icon.svg."""
- canvas = Image.new("RGBA", (size, size), (0, 0, 0, 0))
- gradient = Image.new("RGBA", (size, size))
- pixels = gradient.load()
- top = (14, 165, 233)
- bottom = (3, 105, 161)
- for y in range(size):
- ratio = y / max(size - 1, 1)
- color = tuple(round(a + (b - a) * ratio) for a, b in zip(top, bottom))
- for x in range(size):
- pixels[x, y] = (*color, 255)
- mask = Image.new("L", (size, size), 0)
- ImageDraw.Draw(mask).rounded_rectangle(
- (0, 0, size - 1, size - 1),
- radius=round(size * 0.22),
- fill=255,
- )
- canvas.paste(gradient, (0, 0), mask)
- draw = ImageDraw.Draw(canvas)
- scale = size / 64
- line_width = round(4.2 * scale)
- m_points = [(18, 46), (18, 22), (28, 36), (38, 22), (38, 46)]
- m_points = [(round(x * scale), round(y * scale)) for x, y in m_points]
- draw.line(m_points, fill="#F8FAFC", width=line_width, joint="curve")
- radius = line_width // 2
- for x, y in m_points:
- draw.ellipse((x - radius, y - radius, x + radius, y + radius), fill="#F8FAFC")
- cyan = "#67E8F9"
- draw.rounded_rectangle(
- tuple(round(value * scale) for value in (38, 22, 50, 34)),
- radius=round(scale),
- outline=cyan,
- width=round(3.2 * scale),
- )
- cx, cy, circle_radius = 48 * scale, 44 * scale, 4.5 * scale
- draw.ellipse(
- (
- round(cx - circle_radius),
- round(cy - circle_radius),
- round(cx + circle_radius),
- round(cy + circle_radius),
- ),
- fill="#F8FAFC",
- outline=cyan,
- width=round(2.4 * scale),
- )
- return canvas
- def main() -> None:
- OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
- source = render_mdiop_icon()
- for size in ICON_SIZES:
- icon = source.resize((size, size), Image.Resampling.LANCZOS)
- icon.save(OUTPUT_DIR / f"icon-{size}.png", optimize=True)
- WEB_ICON.parent.mkdir(parents=True, exist_ok=True)
- source.resize((512, 512), Image.Resampling.LANCZOS).save(WEB_ICON, optimize=True)
- splash = Image.new("RGB", (1080, 1920), "#F8FAFC")
- splash_icon = source.resize((320, 320), Image.Resampling.LANCZOS)
- splash.paste(splash_icon, ((1080 - 320) // 2, 650), splash_icon)
- splash.save(OUTPUT_DIR / "splash-1080x1920.png", optimize=True)
- if __name__ == "__main__":
- main()
|