/** * 🖼️ 14 风格 × 100 = 1400 个 透明底 PNG 渲染脚本(512×512) * 读取 output/agent-avatars-png/avatars/{style}/{file}.svg, * Chrome headless 截图 → 透明背景 PNG(SVG 自带圆底,外部透明)。 * * 用法:node scripts/gen-avatars-png.js */ 'use strict'; const fs = require('fs'); const path = require('path'); const { spawn } = require('child_process'); const ROOT = path.resolve(__dirname, '..'); const SVG_ROOT = path.join(ROOT, 'output', 'agent-avatars-png', 'avatars'); const TMP_DIR = path.join(ROOT, 'output', '.tmp-av'); const CHROME = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe'; const SIZE = 512; // —— 1. 收集全部 SVG 文件 —— const files = []; for (const dir of fs.readdirSync(SVG_ROOT, { withFileTypes: true })) { if (!dir.isDirectory()) continue; for (const f of fs.readdirSync(path.join(SVG_ROOT, dir.name))) { if (f.endsWith('.svg')) files.push(path.join(dir.name, f)); } } files.sort(); console.log('📦 待渲染 SVG:' + files.length + ' 个'); // —— 2. 生成 HTML(透明背景 + SVG 居中,放大到 SIZE)—— fs.mkdirSync(TMP_DIR, { recursive: true }); const jobs = files.map((rel, i) => { const svg = fs.readFileSync(path.join(SVG_ROOT, rel), 'utf8'); const html = `