| 1 | // Draws the app's icons from the g1t mark (packages/theme/mark.svg): |
| 2 | // `npm run icons -w @g1t/mobile` after the mark or the background changes. |
| 3 | // |
| 4 | // - icon.png: the store and iOS icon, the mark on g1t's background. |
| 5 | // - android-icon-foreground.png: the adaptive icon's mark, inside the |
| 6 | // middle 66% Android keeps whatever the launcher's mask. |
| 7 | // - android-icon-monochrome.png: the same in white, for themed icons. |
| 8 | // - splash-icon.png: the mark alone, on the splash screen's background. |
| 9 | // - notification-icon.png: the mark in white on nothing, as Android draws |
| 10 | // a notification's small icon (tinted with the accent). |
| 11 | import { readFile } from "node:fs/promises"; |
| 12 | import { fileURLToPath } from "node:url"; |
| 13 | import sharp from "sharp"; |
| 14 | |
| 15 | const here = (path) => fileURLToPath(new URL(path, import.meta.url)); |
| 16 | const mark = await readFile(here("../../../packages/theme/mark.svg"), "utf8"); |
| 17 | const BACKGROUND = "#0f0f11"; |
| 18 | |
| 19 | /** The mark at `scale` of a `size` square, recoloured, on `background` or nothing. */ |
| 20 | async function draw(file, { size, scale, color, background }) { |
| 21 | const inner = Math.round(size * scale); |
| 22 | const svg = Buffer.from(mark.replace(/#b6a8ff/g, color ?? "#b6a8ff").replace("<svg ", `<svg width="${inner}" height="${inner}" `)); |
| 23 | const glyph = await sharp(svg, { density: 72 * (inner / 80) }).resize(inner, inner).png().toBuffer(); |
| 24 | await sharp({ create: { width: size, height: size, channels: 4, background: background ?? { r: 0, g: 0, b: 0, alpha: 0 } } }) |
| 25 | .composite([{ input: glyph, gravity: "centre" }]) |
| 26 | .png() |
| 27 | .toFile(here(`../assets/images/${file}`)); |
| 28 | } |
| 29 | |
| 30 | await draw("icon.png", { size: 1024, scale: 0.62, background: BACKGROUND }); |
| 31 | await draw("android-icon-foreground.png", { size: 1024, scale: 0.46 }); |
| 32 | await draw("android-icon-monochrome.png", { size: 1024, scale: 0.46, color: "#ffffff" }); |
| 33 | await draw("splash-icon.png", { size: 512, scale: 0.9 }); |
| 34 | await draw("notification-icon.png", { size: 96, scale: 0.8, color: "#ffffff" }); |
| 35 | console.log("Drew icon.png, android-icon-foreground.png, android-icon-monochrome.png, splash-icon.png and notification-icon.png."); |