// Renders mark.svg (the Graphley app icon) to the site's PNG icons. // Run from the repository root: node tools/render-icons.js [out-dir-for-sibling-icons] // Writes assets/icon.png (512, rounded), favicon.png (64, rounded), assets/apple-touch-icon.png // (180, square; iOS rounds it). With an out dir it also writes graphley-96.png and graphley-144.png //. const fs = require('fs'); const path = require('path'); const { chromium } = require('playwright'); const root = path.resolve(__dirname, '..'); const svg = fs.readFileSync(path.join(root, 'mark.svg'), 'utf8'); const rounded = (size) => `
${svg.replace('
`; const square = (size) => `${svg.replace('`; (async () => { const browser = await chromium.launch(process.env.PW_CHROME ? { executablePath: process.env.PW_CHROME } : {}); const shot = async (html, size, file) => { const page = await browser.newPage({ viewport: { width: size, height: size } }); await page.setContent(html); await page.screenshot({ path: file, omitBackground: true }); await page.close(); }; await shot(rounded(512), 512, path.join(root, 'assets/icon.png')); await shot(rounded(64), 64, path.join(root, 'favicon.png')); await shot(square(180), 180, path.join(root, 'assets/apple-touch-icon.png')); const out = process.argv[2]; if (out) { await shot(rounded(96), 96, path.join(out, 'graphley-96.png')); await shot(rounded(144), 144, path.join(out, 'graphley-144.png')); } await browser.close(); })();