// Erzeugt PWA-Icons aus dem echten App-Logo (logo_v3.svg) auf hellem Grund. // Läuft manuell: `node scripts/generate-pwa-icons.mjs` import sharp from "sharp"; import { readFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { dirname, join } from "node:path"; const root = join(dirname(fileURLToPath(import.meta.url)), ".."); const staticDir = join(root, "static"); const BG = "#f0f5f1"; // wald-50 (wie Header-Hintergrund) const logoSvg = readFileSync( join(root, "..", "cms_content", "windwiderstand", "assets", "logo_v3.svg"), "utf8", ); async function makeIcon(size, logoRatio, out) { const logoPx = Math.round(size * logoRatio); const logo = await sharp(Buffer.from(logoSvg), { density: 384 }) .resize(logoPx, logoPx, { fit: "contain", background: { r: 0, g: 0, b: 0, alpha: 0 } }) .png() .toBuffer(); const pad = Math.round((size - logoPx) / 2); await sharp({ create: { width: size, height: size, channels: 4, background: BG } }) .composite([{ input: logo, top: pad, left: pad }]) .png() .toFile(join(staticDir, out)); console.log("wrote", out, `${size}px`); } await makeIcon(192, 0.78, "icon-192.png"); await makeIcon(512, 0.78, "icon-512.png"); await makeIcon(512, 0.6, "icon-maskable-512.png"); // mehr Rand für Maskable-Safe-Zone await makeIcon(180, 0.78, "apple-touch-icon.png");