Skip to content
35 linesCodeBlameRaw
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).
11import { readFile } from "node:fs/promises";
12import { fileURLToPath } from "node:url";
13import sharp from "sharp";
14
15const here = (path) => fileURLToPath(new URL(path, import.meta.url));
16const mark = await readFile(here("../../../packages/theme/mark.svg"), "utf8");
17const BACKGROUND = "#0f0f11";
18
19/** The mark at `scale` of a `size` square, recoloured, on `background` or nothing. */
20async 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
30await draw("icon.png", { size: 1024, scale: 0.62, background: BACKGROUND });
31await draw("android-icon-foreground.png", { size: 1024, scale: 0.46 });
32await draw("android-icon-monochrome.png", { size: 1024, scale: 0.46, color: "#ffffff" });
33await draw("splash-icon.png", { size: 512, scale: 0.9 });
34await draw("notification-icon.png", { size: 96, scale: 0.8, color: "#ffffff" });
35console.log("Drew icon.png, android-icon-foreground.png, android-icon-monochrome.png, splash-icon.png and notification-icon.png.");