Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(brand): render the wordmark onto an exact canvas and generate the Play developer-page set

nirholas013e076847e9
diff --git a/docs/ops/play-store-developer-page.md b/docs/ops/play-store-developer-page.md
new file mode 100644
index 000000000..e21e2b774
--- /dev/null
+++ b/docs/ops/play-store-developer-page.md
@@ -0,0 +1,80 @@
+# Google Play developer page
+
+Everything the Play Console asks for under **Developer account -> Developer
+page**, with the artwork generated from the brand source rather than exported by
+hand. Regenerate the images with:
+
+```bash
+npm run build:play-assets
+```
+
+That runs [`scripts/render-play-assets.mjs`](../../scripts/render-play-assets.mjs)
+and writes both files into `public/brand/play/`.
+
+## What Play asks for, and what to upload
+
+| Console field | Play's spec | Upload |
+| --- | --- | --- |
+| Developer icon | JPEG or 24-bit PNG (not transparent), 512 x 512, up to 1 MB | `public/brand/play/three-ws-play-developer-icon-512x512.png` |
+| Header image | JPEG or 24-bit PNG (not transparent), 4096 x 2304, up to 1 MB | `public/brand/play/three-ws-play-header-4096x2304.png` |
+| Developer website | Any URL | `https://three.ws` |
+| Developer email address | Public on the listing | `[email protected]` |
+| Promotional text | Up to 140 characters | See below |
+| Featured app | Optional, needs a published app | Leave unset until the first app ships |
+
+### Promotional text
+
+Shown at the bottom of the developer page, 140 characters maximum. Use this one:
+
+```
+Give your AI a body. Create rigged 3D avatars in seconds, embed them anywhere, and let your agents earn on the open web.
+```
+
+That is 120 characters, opening on the site's own tagline (`site.tagline` in
+[`data/pages.json`](../../data/pages.json)) so the store page and the site say
+the same thing. Two alternates, both inside the limit, if the emphasis should
+sit on the developer surface instead:
+
+```
+Give your AI a body. Build, embed, and monetize autonomous AI agents with real 3D avatars, on-chain identity, and pay-per-call APIs.
+```
+
+```
+three.ws gives your AI a body: rigged 3D avatars, on-chain identity, and pay-per-call APIs for autonomous agents on the open web.
+```
+
+Keep it to what the platform does. The store listing is not the place to
+promote a token.
+
+## Why the generator exists rather than a hand export
+
+Play rejects an upload outright when a constraint is missed, and the two easy
+ones to miss are both invisible in a preview:
+
+- **24-bit, not transparent.** A PNG written by a canvas is always 32-bit RGBA,
+ so the alpha channel has to be stripped deliberately. Both files are asserted
+ to be 3-channel before they are written.
+- **1 MB ceiling.** Asserted on the actual byte length, not estimated.
+
+Dimensions are asserted too. A wrong file fails in the terminal instead of in
+the Console.
+
+Two artwork decisions are worth knowing about:
+
+- **The header is the wordmark centred on black**, drawn by
+ [`scripts/render-wordmark.mjs`](../../scripts/render-wordmark.mjs) against the
+ same Space Grotesk files the site serves, so the banner can never drift from
+ the product's typography. It is centred by the pixels that actually landed
+ rather than by the font metrics that predicted them. Details in
+ [`marketing/brand/README.md`](../../marketing/brand/README.md).
+- **The developer icon is inset to 82%.** Play masks it to a circle, and the
+ shipped app mark (`public/pwa-512x512.png`) is drawn edge to edge, so at full
+ bleed the cube's vertices clip.
+
+## Before any of this can be saved
+
+The developer page fields sit behind Android developer verification: the account
+owner has to open the Play Console app on a physical Android device, sign in as
+the owner account, and pick the `three.ws` developer account. There is no
+desktop or emulator path, by design. Until that clears, the Console shows the
+setup banner instead of saving the profile.
diff --git a/marketing/brand/README.md b/marketing/brand/README.md
index d8e9cbb08..14339f39e 100644
--- a/marketing/brand/README.md
+++ b/marketing/brand/README.md
@@ -33,6 +33,46 @@ production), screenshots each element with `omitBackground`, and writes:
Commit the regenerated files with the source change. They ship with the site,
so `/press` and the zip are always the current artwork.
+## Full-bleed wordmark
+
+The lockups above are trimmed artwork sized to themselves. When a slot wants an
+exact canvas instead (a wallpaper, a title card, a stage backdrop, a store
+banner), render the wordmark centred on one:
+
+```bash
+npm run build:wordmark
+```
+
+That runs [`scripts/render-wordmark.mjs`](../../scripts/render-wordmark.mjs) and writes:
+
+| Output | Size | Use |
+| --- | --- | --- |
+| `public/brand/three-ws-wordmark-on-dark-4096x2304.png` | 4096 x 2304 | White type on black. The default. |
+| `public/brand/three-ws-wordmark-on-light-4096x2304.png` | 4096 x 2304 | Dark type on white. |
+| `public/brand/three-ws-wordmark-transparent-4096x2304.png` | 4096 x 2304 | White type, alpha ground, to drop on your own colour. |
+
+Any canvas and framing:
+
+```bash
+node scripts/render-wordmark.mjs --width=1920 --height=1080 --fit=0.5
+node scripts/render-wordmark.mjs --variants=on-dark --out=/tmp/banner
+```
+
+`--fit` is the wordmark's ink width as a fraction of canvas width (default
+`0.46`, which leaves roughly a quarter of the width clear on each side).
+
+Three details are load-bearing:
+
+- The type is drawn on a 2D canvas rather than screenshotted, so the file is
+ exactly the pixel size asked for with no crop or rounding.
+- It is centred by the pixels that actually landed, not by the font metrics that
+ predicted them: the renderer draws once, reads back the alpha channel, and
+ redraws with the correction. Metrics and the rasteriser disagree by a pixel or
+ two, and lowercase with ascenders and no descenders rides visibly low when its
+ line box is centred instead of its ink box.
+- The two opaque variants ship with the alpha channel stripped. A store banner
+ slot (Play's feature graphic among them) rejects 32-bit PNG outright.
+
## Why it renders in a browser
The wordmark is set in Space Grotesk, the display face the site already uses.
diff --git a/package.json b/package.json
index 21e639497..ebce5eb6c 100644
--- a/package.json
+++ b/package.json
@@ -162,6 +162,8 @@
"build:discovery": "node scripts/build-discovery-cards.mjs",
"build:openai-cards": "node scripts/render-openai-social-cards.mjs",
"build:brand-assets": "node scripts/render-brand-assets.mjs",
+ "build:wordmark": "node scripts/render-wordmark.mjs",
+ "build:play-assets": "node scripts/render-play-assets.mjs",
"build:dapp-store-media": "node solana-mobile/scripts/make-media.mjs",
"build:dapp-store-previews": "node solana-mobile/scripts/make-screenshots.mjs",
"render:pumpfun-verified": "node scripts/render-pumpfun-verified.mjs",
diff --git a/public/brand/play/three-ws-play-app-icon-512x512.png b/public/brand/play/three-ws-play-app-icon-512x512.png
new file mode 100644
index 000000000..03766dbf7
Binary files /dev/null and b/public/brand/play/three-ws-play-app-icon-512x512.png differ
diff --git a/public/brand/play/three-ws-play-developer-icon-512x512.png b/public/brand/play/three-ws-play-developer-icon-512x512.png
new file mode 100644
index 000000000..f7e6b3213
Binary files /dev/null and b/public/brand/play/three-ws-play-developer-icon-512x512.png differ
diff --git a/public/brand/play/three-ws-play-feature-1024x500.png b/public/brand/play/three-ws-play-feature-1024x500.png
new file mode 100644
index 000000000..3b6e7b873
Binary files /dev/null and b/public/brand/play/three-ws-play-feature-1024x500.png differ
diff --git a/public/brand/play/three-ws-play-header-4096x2304.png b/public/brand/play/three-ws-play-header-4096x2304.png
new file mode 100644
index 000000000..4f103f1a3
Binary files /dev/null and b/public/brand/play/three-ws-play-header-4096x2304.png differ
diff --git a/public/brand/three-ws-wordmark-on-dark-4096x2304.png b/public/brand/three-ws-wordmark-on-dark-4096x2304.png
new file mode 100644
index 000000000..4f103f1a3
Binary files /dev/null and b/public/brand/three-ws-wordmark-on-dark-4096x2304.png differ
diff --git a/public/brand/three-ws-wordmark-on-light-4096x2304.png b/public/brand/three-ws-wordmark-on-light-4096x2304.png
new file mode 100644
index 000000000..6793ab185
Binary files /dev/null and b/public/brand/three-ws-wordmark-on-light-4096x2304.png differ
diff --git a/public/brand/three-ws-wordmark-transparent-4096x2304.png b/public/brand/three-ws-wordmark-transparent-4096x2304.png
new file mode 100644
index 000000000..b05474a17
Binary files /dev/null and b/public/brand/three-ws-wordmark-transparent-4096x2304.png differ
diff --git a/scripts/render-play-assets.mjs b/scripts/render-play-assets.mjs
new file mode 100644
index 000000000..b3c595861
--- /dev/null
+++ b/scripts/render-play-assets.mjs
@@ -0,0 +1,140 @@
+#!/usr/bin/env node
+/**
+ * Renders the Google Play developer-page image set.
+ *
+ * Play states two hard constraints on both slots, and rejects the upload rather
+ * than degrading if either is missed: "JPEG or 24-bit PNG (not transparent)"
+ * and "Up to 1 MB". A PNG written by a canvas is always 32-bit RGBA, so the
+ * alpha channel has to come off explicitly. Every constraint below is asserted
+ * after the bytes exist, so a wrong file fails here and not in the Console.
+ *
+ * Developer icon 512 x 512 Shown as a circle next to the developer name.
+ * Header image 4096 x 2304 Full-bleed banner at the top of the page.
+ * App icon 512 x 512 The store listing's icon.
+ * Feature graphic 1024 x 500 Promotional banner for the store listing.
+ *
+ * The header is the wordmark centred on black, drawn by scripts/render-wordmark.mjs
+ * so the type comes from the same Space Grotesk files the site serves. The icon
+ * is the shipped app mark (public/pwa-512x512.png) inset for the circular crop:
+ * at full bleed the cube's vertices sit outside the circle and get clipped.
+ *
+ * Usage:
+ * npm run build:play-assets
+ * node scripts/render-play-assets.mjs --out=/tmp/play
+ */
+import { mkdirSync, statSync, writeFileSync } from 'node:fs';
+import { dirname, join, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import sharp from 'sharp';
+import { renderWordmarks, renderPage } from './render-wordmark.mjs';
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+const ROOT = resolve(__dirname, '..');
+const PUBLIC = join(ROOT, 'public');
+
+const args = Object.fromEntries(process.argv.slice(2).map((a) => {
+ const m = a.match(/^--([^=]+)(?:=(.*))?$/);
+ return m ? [m[1], m[2] ?? true] : [a, true];
+}));
+const OUT_DIR = args.out ? resolve(String(args.out)) : join(PUBLIC, 'brand/play');
+
+/** Play's stated ceiling for both slots. */
+const MAX_BYTES = 1024 * 1024;
+const GROUND = '#000000';
+/* The mark is drawn edge to edge, and Play masks the developer icon to a
+ circle. 0.82 keeps the cube's vertices inside that circle with room to
+ spare, which full bleed does not. */
+const ICON_INSET = 0.82;
+const SOURCE_MARK = join(PUBLIC, 'pwa-512x512.png');
+
+mkdirSync(OUT_DIR, { recursive: true });
+
+/** Flatten onto the brand ground and drop the alpha channel Play refuses. */
+async function toOpaquePng(pipeline) {
+ return pipeline.flatten({ background: GROUND }).removeAlpha().png({ compressionLevel: 9 }).toBuffer();
+}
+
+/** Fail loudly here rather than shipping a file the Console will bounce. */
+async function assertPlayReady(label, buffer, width, height) {
+ const meta = await sharp(buffer).metadata();
+ const problems = [];
+ if (meta.width !== width || meta.height !== height) {
+ problems.push(`is ${meta.width}x${meta.height}, Play requires ${width}x${height}`);
+ }
+ if (meta.hasAlpha || meta.channels !== 3) {
+ problems.push(`has ${meta.channels} channels, Play requires 24-bit PNG with no transparency`);
+ }
+ if (buffer.length > MAX_BYTES) {
+ problems.push(`is ${(buffer.length / 1024 / 1024).toFixed(2)} MB, Play's ceiling is 1 MB`);
+ }
+ if (problems.length) throw new Error(`${label} ${problems.join('; ')}`);
+ return meta;
+}
+
+const written = [];
+
+/* Header image: the wordmark centred on the brand ground. */
+const [header] = await renderWordmarks([
+ { width: 4096, height: 2304, bg: GROUND, fg: '#ffffff' },
+]);
+await assertPlayReady('header image', header.buffer, 4096, 2304);
+written.push(['three-ws-play-header-4096x2304.png', header.buffer, `wordmark ink ${header.ink.width}x${header.ink.height}, centred`]);
+
+/* Developer icon: the shipped app mark, inset for the circular crop. */
+const inner = Math.round(512 * ICON_INSET);
+const pad = Math.round((512 - inner) / 2);
+const icon = await toOpaquePng(
+ sharp({ create: { width: 512, height: 512, channels: 4, background: GROUND } }).composite([{
+ input: await sharp(SOURCE_MARK).resize(inner, inner, { fit: 'contain', background: { r: 0, g: 0, b: 0, alpha: 0 } }).png().toBuffer(),
+ top: pad,
+ left: pad,
+ }]).png(),
+);
+await assertPlayReady('developer icon', icon, 512, 512);
+written.push(['three-ws-play-developer-icon-512x512.png', icon, `mark inset to ${Math.round(ICON_INSET * 100)}% for the circular crop`]);
+
+/* App icon for the store listing. Same artwork as the dApp Store slot: the
+ shipped mark flattened onto the brand ground. Play draws this one with its
+ own rounded-corner mask rather than a circle, so it keeps the full bleed the
+ developer icon gives up. */
+const appIcon = await toOpaquePng(sharp(SOURCE_MARK).resize(512, 512));
+await assertPlayReady('app icon', appIcon, 512, 512);
+written.push(['three-ws-play-app-icon-512x512.png', appIcon, 'shipped app mark on the brand ground']);
+
+/* Feature graphic. Play's own guidance is to keep screenshots and small text
+ out of this slot: it is scaled down hard in the store and cropped at the
+ edges on some surfaces, so everything that carries meaning sits in the
+ middle and is set large. Brand ground, the lockup, one line of copy. */
+const FEATURE_HTML = `
+<div style="
+ width:1024px;height:500px;display:flex;flex-direction:column;
+ align-items:center;justify-content:center;gap:26px;
+ background:#000000;
+ font-family:'Space Grotesk',Inter,sans-serif;
+">
+ <div style="display:flex;align-items:center;gap:26px;">
+ <img src="/marketing/openai-select-partner/cards/three-ws-mark.png" alt=""
+ style="display:block;height:132px;width:auto;" />
+ <span style="
+ font-size:104px;font-weight:600;letter-spacing:-0.045em;line-height:1;
+ color:#ffffff;white-space:nowrap;padding-right:6px;padding-bottom:8px;
+ ">three.ws</span>
+ </div>
+ <p style="
+ font-family:Inter,sans-serif;font-size:30px;font-weight:400;line-height:1.35;
+ letter-spacing:-0.01em;color:rgba(255,255,255,0.72);text-align:center;max-width:880px;
+ ">Turn a photo or a prompt into 3D models and AI agents.</p>
+</div>`;
+const feature = await renderPage(FEATURE_HTML, { width: 1024, height: 500 });
+await assertPlayReady('feature graphic', feature, 1024, 500);
+written.push(['three-ws-play-feature-1024x500.png', feature, 'lockup and one line of copy, no small text']);
+
+for (const [name, buffer, note] of written) {
+ const out = join(OUT_DIR, name);
+ writeFileSync(out, buffer);
+ const meta = await sharp(out).metadata();
+ console.log(
+ `${name} ${meta.width}x${meta.height} ${meta.channels}-channel opaque ` +
+ `${Math.round(statSync(out).size / 1024)} KB / 1024 KB (${note}) -> ${out}`,
+ );
+}
diff --git a/scripts/render-wordmark.mjs b/scripts/render-wordmark.mjs
new file mode 100644
index 000000000..ae3e52bd9
--- /dev/null
+++ b/scripts/render-wordmark.mjs
@@ -0,0 +1,309 @@
+#!/usr/bin/env node
+/**
+ * Renders the three.ws wordmark centred on a fixed-size canvas.
+ *
+ * This is the full-bleed companion to scripts/render-brand-assets.mjs. That
+ * renderer exports trimmed, transparent marks sized to their own artwork; this
+ * one fills an exact pixel canvas (4096 x 2304 by default, 16:9) with the
+ * wordmark alone, which is what a wallpaper, a title card, a stage backdrop, or
+ * a store banner needs.
+ *
+ * The type is drawn on a 2D canvas inside a real browser, against the same
+ * /fonts/*.woff2 files the site serves, so the wordmark can never drift from
+ * the product's typography. Drawing rather than screenshotting means the output
+ * is exactly the requested pixel dimensions with no crop or rounding.
+ *
+ * Importable: scripts/render-play-assets.mjs calls renderWordmarks() for the
+ * Play developer-page header rather than re-deriving the font plumbing.
+ *
+ * Usage:
+ * npm run build:wordmark
+ * node scripts/render-wordmark.mjs --width=1920 --height=1080 --fit=0.5
+ * node scripts/render-wordmark.mjs --out=/tmp/wordmark --variants=on-dark
+ */
+import { createServer } from 'node:http';
+import { createReadStream, existsSync, mkdirSync, statSync, writeFileSync } from 'node:fs';
+import { dirname, extname, join, normalize, resolve } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { chromium } from 'playwright';
+import sharp from 'sharp';
+
+const __dirname = dirname(fileURLToPath(import.meta.url));
+const ROOT = resolve(__dirname, '..');
+const PUBLIC = join(ROOT, 'public');
+
+export const WORD = 'three.ws';
+/* Matches the lockup in marketing/brand/brand-assets.html: the wordmark is one
+ mark, not two, so weight and tracking are copied rather than re-chosen. */
+export const WEIGHT = 600;
+export const TRACKING = -0.045; // em
+/** Wordmark ink width as a fraction of canvas width. Leaves real clear space. */
+export const FIT = 0.46;
+
+export const VARIANTS = [
+ { id: 'on-dark', file: 'three-ws-wordmark-on-dark', bg: '#000000', fg: '#ffffff' },
+ { id: 'on-light', file: 'three-ws-wordmark-on-light', bg: '#ffffff', fg: '#0b0d0c' },
+ { id: 'transparent', file: 'three-ws-wordmark-transparent', bg: null, fg: '#ffffff' },
+];
+
+const MIME = { '.css': 'text/css; charset=utf-8', '.woff2': 'font/woff2', '.html': 'text/html; charset=utf-8' };
+
+/** Resolve a request path against public/ first, then the repo root. */
+function resolveAsset(urlPath) {
+ const rel = normalize(decodeURIComponent(urlPath)).replace(/^(\.\.[/\\])+/, '').replace(/^[/\\]+/, '');
+ for (const base of [PUBLIC, ROOT]) {
+ const abs = join(base, rel);
+ if (abs.startsWith(base) && existsSync(abs) && statSync(abs).isFile()) return abs;
+ }
+ return null;
+}
+
+/**
+ * Serve the repo over HTTP so /fonts/*.woff2 resolve exactly as in production.
+ * A file:// load silently falls back to a system face and ships a wrong logo.
+ */
+function startServer() {
+ const server = createServer((req, res) => {
+ const url = new URL(req.url, 'http://localhost');
+ if (url.pathname === '/') {
+ res.writeHead(200, { 'content-type': MIME['.html'] });
+ res.end('<!doctype html><meta charset="utf-8"><link rel="stylesheet" href="/fonts/fonts.css"><body></body>');
+ return;
+ }
+ const abs = resolveAsset(url.pathname);
+ if (!abs) { res.writeHead(404).end('not found'); return; }
+ res.writeHead(200, { 'content-type': MIME[extname(abs)] || 'application/octet-stream' });
+ createReadStream(abs).pipe(res);
+ });
+ return new Promise((ok) => server.listen(0, '127.0.0.1', () => ok(server)));
+}
+
+/**
+ * Screenshot an HTML fragment at an exact pixel size, against the repo's own
+ * fonts. The page is served over HTTP so /fonts/*.woff2 resolve as they do in
+ * production; a file:// load silently substitutes a system face.
+ *
+ * @param {string} bodyHtml markup placed inside a full-bleed body
+ * @param {{width:number,height:number}} size
+ * @returns {Promise<Buffer>} opaque PNG at exactly the requested size
+ */
+export async function renderPage(bodyHtml, { width, height }) {
+ const server = await startServer();
+ const origin = `http://127.0.0.1:${server.address().port}`;
+ const browser = await chromium.launch();
+ const page = await browser.newPage({ viewport: { width, height }, deviceScaleFactor: 1 });
+
+ const failures = [];
+ page.on('requestfailed', (r) => failures.push(r.url()));
+ page.on('response', (r) => { if (r.status() >= 400) failures.push(`${r.status()} ${r.url()}`); });
+
+ try {
+ await page.goto(origin + '/', { waitUntil: 'networkidle' });
+ await page.setContent(
+ `<!doctype html><meta charset="utf-8">` +
+ `<base href="${origin}/">` +
+ `<link rel="stylesheet" href="/fonts/fonts.css">` +
+ `<style>*{box-sizing:border-box;margin:0;padding:0}` +
+ `html,body{width:${width}px;height:${height}px;overflow:hidden}</style>` +
+ `<body>${bodyHtml}</body>`,
+ { waitUntil: 'networkidle' },
+ );
+ await page.evaluate(() => document.fonts.ready);
+ const ok = await page.evaluate(() => document.fonts.check('600 100px "Space Grotesk"'));
+ if (!ok) throw new Error('Space Grotesk did not load; the artwork would render in a fallback face');
+
+ const shot = await page.screenshot({ clip: { x: 0, y: 0, width, height } });
+ if (failures.length) {
+ throw new Error('assets failed to load, the artwork rendered with fallbacks:\n ' + failures.join('\n '));
+ }
+ return sharp(shot).removeAlpha().png({ compressionLevel: 9 }).toBuffer();
+ } finally {
+ await browser.close();
+ server.close();
+ }
+}
+
+/**
+ * Draw the wordmark centred on each requested canvas.
+ *
+ * @param {Array<{width:number,height:number,bg:string|null,fg:string,fit?:number}>} specs
+ * @returns {Promise<Array<{buffer:Buffer,size:number,ink:object,offset:object}>>}
+ */
+export async function renderWordmarks(specs) {
+ const server = await startServer();
+ const origin = `http://127.0.0.1:${server.address().port}`;
+ const browser = await chromium.launch();
+ const page = await browser.newPage();
+
+ const failures = [];
+ page.on('requestfailed', (r) => failures.push(r.url()));
+ page.on('response', (r) => { if (r.status() >= 400) failures.push(`${r.status()} ${r.url()}`); });
+
+ try {
+ await page.goto(origin + '/', { waitUntil: 'networkidle' });
+
+ /* A canvas silently substitutes a system face for a font it cannot see,
+ which ships a wrong-looking logo rather than an error. Load it
+ explicitly and assert it took before anything is drawn. */
+ const fontOk = await page.evaluate(async ({ weight, word }) => {
+ await document.fonts.load(`${weight} 100px "Space Grotesk"`, word);
+ await document.fonts.ready;
+ return document.fonts.check(`${weight} 100px "Space Grotesk"`);
+ }, { weight: WEIGHT, word: WORD });
+ if (!fontOk) throw new Error('Space Grotesk did not load; the wordmark would render in a fallback face');
+
+ const out = [];
+ for (const spec of specs) {
+ const drawn = await page.evaluate(async (cfg) => {
+ const canvas = document.createElement('canvas');
+ canvas.width = cfg.width;
+ canvas.height = cfg.height;
+ const ctx = canvas.getContext('2d', { willReadFrequently: true });
+ if (!('letterSpacing' in ctx)) throw new Error('canvas letterSpacing is unsupported; tracking would be wrong');
+
+ const applyFont = (size) => {
+ ctx.font = `${cfg.weight} ${size}px "Space Grotesk"`;
+ ctx.letterSpacing = `${cfg.tracking * size}px`;
+ };
+ /** Ink box reported by the font metrics, before rasterisation. */
+ const measure = (size) => {
+ applyFont(size);
+ const m = ctx.measureText(cfg.word);
+ return {
+ width: m.actualBoundingBoxLeft + m.actualBoundingBoxRight,
+ height: m.actualBoundingBoxAscent + m.actualBoundingBoxDescent,
+ left: m.actualBoundingBoxLeft,
+ ascent: m.actualBoundingBoxAscent,
+ };
+ };
+
+ /* Ink width scales linearly with font size, so one probe gives the
+ exact size for the target width. */
+ const probe = 1000;
+ const size = (probe * (cfg.width * cfg.fit)) / measure(probe).width;
+ const ink = measure(size);
+
+ /** Bounds of what was actually painted, read back from the alpha channel. */
+ const paintedBounds = () => {
+ const { data } = ctx.getImageData(0, 0, cfg.width, cfg.height);
+ let minX = cfg.width, maxX = -1, minY = cfg.height, maxY = -1;
+ for (let y = 0; y < cfg.height; y++) {
+ for (let x = 0; x < cfg.width; x++) {
+ if (data[(y * cfg.width + x) * 4 + 3] > 8) {
+ if (x < minX) minX = x;
+ if (x > maxX) maxX = x;
+ if (y < minY) minY = y;
+ if (y > maxY) maxY = y;
+ }
+ }
+ }
+ return { minX, maxX, minY, maxY, cx: (minX + maxX + 1) / 2, cy: (minY + maxY + 1) / 2 };
+ };
+
+ /* Position by the ink box, not the line box: lowercase with
+ ascenders and no descenders rides visibly low when its line box
+ is centred. */
+ const draw = (dx, dy) => {
+ ctx.clearRect(0, 0, cfg.width, cfg.height);
+ applyFont(size);
+ ctx.fillStyle = cfg.fg;
+ ctx.textAlign = 'left';
+ ctx.textBaseline = 'alphabetic';
+ ctx.fillText(
+ cfg.word,
+ (cfg.width - ink.width) / 2 + ink.left + dx,
+ (cfg.height - ink.height) / 2 + ink.ascent + dy,
+ );
+ };
+
+ /* Font metrics and the rasteriser disagree by a pixel or two once
+ antialiasing is on. Draw once on a transparent ground, measure
+ the pixels that actually landed, and redraw with that
+ correction, so the painted glyphs are centred rather than the
+ metrics that predicted them. */
+ draw(0, 0);
+ const first = paintedBounds();
+ if (first.maxX < 0) throw new Error('nothing was painted; the wordmark failed to render');
+ draw(cfg.width / 2 - first.cx, cfg.height / 2 - first.cy);
+ const final = paintedBounds();
+
+ /* The background goes on underneath, so the correction pass above
+ reads a clean alpha channel regardless of variant. */
+ if (cfg.bg) {
+ ctx.globalCompositeOperation = 'destination-over';
+ ctx.fillStyle = cfg.bg;
+ ctx.fillRect(0, 0, cfg.width, cfg.height);
+ ctx.globalCompositeOperation = 'source-over';
+ }
+
+ const url = canvas.toDataURL('image/png');
+ return {
+ data: url.slice(url.indexOf(',') + 1),
+ size,
+ ink: { width: final.maxX - final.minX + 1, height: final.maxY - final.minY + 1 },
+ offset: { x: final.cx - cfg.width / 2, y: final.cy - cfg.height / 2 },
+ };
+ }, {
+ width: spec.width,
+ height: spec.height,
+ fit: spec.fit ?? FIT,
+ word: WORD,
+ weight: WEIGHT,
+ tracking: TRACKING,
+ bg: spec.bg,
+ fg: spec.fg,
+ });
+
+ /* An opaque asset must not carry an alpha channel: a store slot
+ (Play's header image and feature graphic among them) requires
+ 24-bit PNG, and the channel is dead weight everywhere else.
+ toDataURL only ever emits RGBA. */
+ const raw = Buffer.from(drawn.data, 'base64');
+ const pipeline = sharp(raw);
+ const buffer = await (spec.bg ? pipeline.removeAlpha() : pipeline)
+ .png({ compressionLevel: 9 })
+ .toBuffer();
+
+ out.push({ ...spec, buffer, size: drawn.size, ink: drawn.ink, offset: drawn.offset });
+ }
+
+ if (failures.length) {
+ throw new Error('assets failed to load, the artwork rendered with fallbacks:\n ' + failures.join('\n '));
+ }
+ return out;
+ } finally {
+ await browser.close();
+ server.close();
+ }
+}
+
+/* CLI */
+if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
+ const args = Object.fromEntries(process.argv.slice(2).map((a) => {
+ const m = a.match(/^--([^=]+)(?:=(.*))?$/);
+ return m ? [m[1], m[2] ?? true] : [a, true];
+ }));
+
+ const width = Number(args.width) || 4096;
+ const height = Number(args.height) || 2304;
+ const fit = Number(args.fit) || FIT;
+ const outDir = args.out ? resolve(String(args.out)) : join(PUBLIC, 'brand');
+
+ const wanted = args.variants ? String(args.variants).split(',').map((s) => s.trim()) : null;
+ const selected = wanted ? VARIANTS.filter((v) => wanted.includes(v.id)) : VARIANTS;
+ if (!selected.length) throw new Error(`no variants matched: ${args.variants}`);
+
+ mkdirSync(outDir, { recursive: true });
+ const rendered = await renderWordmarks(selected.map((v) => ({ ...v, width, height, fit })));
+
+ for (const r of rendered) {
+ const out = join(outDir, `${r.file}-${width}x${height}.png`);
+ writeFileSync(out, r.buffer);
+ const kb = Math.round(statSync(out).size / 1024);
+ console.log(
+ `${r.file}-${width}x${height}.png ${width}x${height} ` +
+ `type ${Math.round(r.size)}px, ink ${r.ink.width}x${r.ink.height}, ` +
+ `off-centre ${r.offset.x.toFixed(1)},${r.offset.y.toFixed(1)}px ${kb} KB -> ${out}`,
+ );
+ }
+}