SPB Git

Repository Public

brand-png.mjs 1.1 KB 15 lines javascript

1// Rasterize the SVG mark with headless Chromium (Playwright from the uqo-eval project): apple-icon 180, icon 512, brand PNGs.2import { chromium } from "/Users/simon-pierreboucher/Desktop/uqo-eval/node_modules/playwright/index.mjs";3import { readFileSync, writeFileSync } from "node:fs";4const svg = readFileSync(new URL("../public/brand/market-atlas-mark.svg", import.meta.url), "utf8");5const browser = await chromium.launch();6for (const [out, size] of [["src/app/apple-icon.png", 180], ["src/app/icon.png", 512], ["public/brand/market-atlas-mark-512.png", 512], ["public/brand/market-atlas-mark-1024.png", 1024]]) {7  const page = await browser.newPage({ viewport: { width: size, height: size }, deviceScaleFactor: 1 });8  await page.setContent(`<html><body style="margin:0;background:transparent">${svg.replace(/width="256" height="256"/, `width="${size}" height="${size}"`)}</body></html>`);9  const buf = await page.screenshot({ omitBackground: true, clip: { x: 0, y: 0, width: size, height: size } });10  writeFileSync(new URL(`../${out}`, import.meta.url), buf);11  console.log(out, size, buf.length, "bytes");12  await page.close();13}14await browser.close();15
Files main
Menu

Theme