/** * 🤖 300 个 bottts 机器人头像候选预览页(资源库 DiceBear bottts 源直选,无需渲染) * 用确定性 seed 生成 300 个不同机器人(过滤负面表情变体),内联 SVG 预览, * 支持勾选,每张可下载白底 PNG,底部可复制已选编号。 * * 用法:node scripts/gen-300-bot-avatars.js */ 'use strict'; const fs = require('fs'); const path = require('path'); const vm = require('vm'); const { generateSeeds } = require('./bot-common'); const ROOT = path.resolve(__dirname, '..'); const OUT_DIR = path.join(ROOT, 'output', 'agent-avatars-png'); const COUNT = 300; // —— 1. 加载 bottts 风格定义 + DiceBear 渲染引擎 —— global.window = global; const styleFile = path.join(ROOT, 'js', 'data', 'sources', 'dicebear-bottts.js'); vm.runInThisContext(fs.readFileSync(styleFile, 'utf8'), { filename: styleFile }); vm.runInThisContext(fs.readFileSync(path.join(ROOT, 'js', 'core', 'dicebear.js'), 'utf8'), { filename: 'js/core/dicebear.js' }); // —— 2. 生成 300 个不同 seed(共享逻辑:过滤负面表情)—— const cards = generateSeeds(seed => HGB_Dicebear.renderAvatar('bottts', seed), COUNT); // —— 3. 预览页(内联 SVG + 勾选交互 + PNG 下载)—— let cardHtml = ''; for (let i = 0; i < cards.length; i++) { const c = cards[i]; const n = String(i + 1).padStart(2, '0'); cardHtml += `\n`; } const html = ` 🤖 300 个 bottts 机器人头像候选 · 勾选后批量渲染

🤖 300 个 bottts 机器人头像候选

资源库 DiceBear bottts 源 · 已过滤负面表情(眩晕/龇牙)· 点击卡片勾选(默认全选)· 每张可直接下载白底 PNG(bot-png/)· 可复制编号批量渲染
已选 0/${COUNT}
${cardHtml}
`; fs.mkdirSync(OUT_DIR, { recursive: true }); fs.writeFileSync(path.join(OUT_DIR, 'preview-300.html'), html, 'utf8'); console.log('🎉 已生成 ' + COUNT + ' 个 bottts 候选(负面表情已过滤)→ output/agent-avatars-png/preview-300.html'); // 校验唯一性 const { createHash } = require('crypto'); const hashes = new Set(); let dup = 0; for (const c of cards) { const h = createHash('md5').update(c.svg).digest('hex'); if (hashes.has(h)) dup++; hashes.add(h); } console.log('头像唯一性:' + (cards.length - dup) + '/' + cards.length + (dup ? '(⚠️ ' + dup + ' 个重复)' : ' ✅'));