#!/usr/bin/env python3 """Erzeugt PNG-Varianten der Marke (Icons, Apple-Touch-Icon, OG-Bild). Abhängigkeiten: Pillow (pip install pillow) – sowie unter macOS `qlmanage` zum Rastern der SVG-Vorlage. Aufruf: python3 scripts/make-images.py """ from __future__ import annotations import subprocess import tempfile from pathlib import Path from PIL import Image, ImageDraw, ImageFont ROOT = Path(__file__).resolve().parent.parent IMG = ROOT / "src" / "assets" / "img" FONTS = [ "/System/Library/Fonts/Supplemental/Arial Bold.ttf", "/System/Library/Fonts/Supplemental/Arial.ttf", "/Library/Fonts/Arial.ttf", ] CREAM = "#fdf8f1" INK = "#2b2118" CORAL = "#d9542f" SUN = "#eda93c" SAGE = "#6f9160" SKY = "#3f7fa6" BERRY = "#a8456a" def font(size: int) -> ImageFont.FreeTypeFont: for path in FONTS: if Path(path).exists(): return ImageFont.truetype(path, size) return ImageFont.load_default(size) def rasterize_svg(svg: Path, size: int) -> Image.Image: """Rastert eine SVG-Datei via Quick Look (macOS) und skaliert sie.""" with tempfile.TemporaryDirectory() as tmp: subprocess.run( ["qlmanage", "-t", "-s", str(size * 2), "-o", tmp, str(svg)], check=True, capture_output=True, ) produced = next(Path(tmp).glob("*.png")) return Image.open(produced).convert("RGBA").resize((size, size), Image.LANCZOS) def maskable(base: Image.Image, size: int, padding_ratio: float = 0.22) -> Image.Image: """Maskable-Icon: Motiv mit Sicherheitsrand, vollflächiger Hintergrund.""" canvas = Image.new("RGBA", (size, size), SUN) inner = int(size * (1 - 2 * padding_ratio)) motif = base.resize((inner, inner), Image.LANCZOS) offset = (size - inner) // 2 canvas.alpha_composite(motif, (offset, offset)) return canvas def make_icons() -> None: svg = IMG / "favicon.svg" for size, name in ((32, "favicon-32.png"), (180, "apple-touch-icon.png"), (192, "icon-192.png"), (512, "icon-512.png")): rasterize_svg(svg, size).save(IMG / name, optimize=True) print(f" ✓ {name}") base = rasterize_svg(svg, 512) maskable(base, 512).save(IMG / "icon-512-maskable.png", optimize=True) print(" ✓ icon-512-maskable.png") # Klassisches favicon.ico für Browser/Tools, die kein SVG/PNG nutzen base.save(IMG / "favicon.ico", sizes=[(16, 16), (32, 32), (48, 48)]) print(" ✓ favicon.ico") def make_og() -> None: W, H = 1200, 630 img = Image.new("RGB", (W, H), CREAM) d = ImageDraw.Draw(img) # Regenbogen in der unteren rechten Ecke cx, cy = 1105, 640 for i, color in enumerate([CORAL, SUN, SAGE, SKY]): r = 430 - i * 62 d.arc([cx - r, cy - r, cx + r, cy + r], start=180, end=270, fill=color, width=30) # Sonne oben rechts sx, sy, sr = 1040, 118, 58 d.ellipse([sx - sr, sy - sr, sx + sr, sy + sr], fill=SUN) # Fünf Punkte (die Rasselbande) dots = [(120, 470, 34, SUN), (200, 520, 26, CORAL), (280, 486, 40, CORAL), (352, 534, 24, SKY), (420, 496, 30, BERRY)] for x, y, r, color in dots: d.ellipse([x - r, y - r, x + r, y + r], fill=color, outline=CREAM, width=6) # Text d.text((96, 150), "Sonjas Rasselbande", font=font(78), fill=INK) d.text((100, 258), "Kindertagespflege in Neuss-Rosellen", font=font(42), fill=CORAL) d.text((100, 330), "Tagesmutter · max. 5 Kinder · ab 6 Monaten", font=font(30), fill="#5c4f44") d.text((100, 380), "sonjasrasselbande.de", font=font(30), fill="#786b5f") img.save(IMG / "og-image.png", optimize=True) print(" ✓ og-image.png (1200×630)") if __name__ == "__main__": print("Icons:") make_icons() print("Social-Preview:") make_og()