-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate-avatars.js
33 lines (26 loc) · 961 Bytes
/
generate-avatars.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import * as core from '@dicebear/core';
import * as collection from '@dicebear/collection';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const outputDir = path.join(__dirname, 'static', 'avatars');
// Ensure the output directory exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Generate 20 avatars
for (let i = 1; i <= 20; i++) {
const avatar = core.createAvatar(collection.micah, {
seed: `avatar-${i}-2`,
size: 128,
backgroundColor: ['b6e3f4', 'c0aede', 'd1d4f9', 'ffd5dc', 'ffdfbf'],
baseColor: ['fff'],
mouth: ['smile', 'smirk']
});
const svg = avatar.toString();
fs.writeFileSync(path.join(outputDir, `${i}.svg`), svg);
console.log(`Generated avatar ${i}.svg`);
}
console.log('Avatar generation complete!');