Branchwell

Graphley / app · graphley.ai / scripts / render-icons.js

Raw 2.2 KB on d80f63aea8f10988b2fe7107ba87bf71b30173fb
1// Renders brand/graphley-icon.svg (the "Stacked tide" icon, same file as graphley-site/mark.svg) to every
2// app icon PNG. Uses Chromium through Playwright, because ImageMagick's built-in SVG renderer once dropped
3// the old icon's gradient and line and shipped a black square with a dot.
4// Run from the repository root: node scripts/render-icons.js
5const fs = require('fs');
6const path = require('path');
7const { chromium } = require('playwright');
8const root = path.resolve(__dirname, '..');
9const svg = fs.readFileSync(path.join(root, 'brand/graphley-icon.svg'), 'utf8').replace('<svg ', '<svg style="display:block;width:100%;height:100%" ');
10
11// macOS icon grid: an 824 pt rounded square centered in 1024, with a soft drop shadow (Apple's template).
12const mac = (size) => {
13 const body = size * 824 / 1024, radius = body * 0.225;
14 return `<html><body style="margin:0;background:transparent"><div style="width:${size}px;height:${size}px;display:grid;place-items:center">
15 <div style="width:${body}px;height:${body}px;border-radius:${radius}px;overflow:hidden;
16 box-shadow:0 ${size * 0.0098}px ${size * 0.0195}px rgba(0,0,0,.28)">${svg}</div></div></body></html>`;
17};
18// iOS: full-bleed opaque square, the system applies the mask.
19const square = (size) => `<html><body style="margin:0"><div style="width:${size}px;height:${size}px">${svg}</div></body></html>`;
20
21(async () => {
22 const browser = await chromium.launch(process.env.PW_CHROME ? { executablePath: process.env.PW_CHROME } : {});
23 const shot = async (html, size, file, transparent = true) => {
24 const page = await browser.newPage({ viewport: { width: size, height: size } });
25 await page.setContent(html);
26 await page.screenshot({ path: path.join(root, file), omitBackground: transparent });
27 await page.close();
28 };
29 for (const size of [16, 32, 64, 128, 256, 512, 1024]) {
30 await shot(mac(size), size, `Apps/Mac/Assets.xcassets/AppIcon.appiconset/icon-${size}.png`);
31 }
32 await shot(square(1024), 1024, 'Apps/iPhone/Assets.xcassets/AppIcon.appiconset/icon-1024.png', false);
33 await shot(mac(1024), 1024, 'brand/graphley-icon-1024.png');
34 await shot(square(1024), 1024, 'brand/graphley-icon-1024-opaque.png', false);
35 await browser.close();
36})();