-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-icons.js
More file actions
49 lines (42 loc) · 1.56 KB
/
Copy pathcreate-icons.js
File metadata and controls
49 lines (42 loc) · 1.56 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
import sharp from 'sharp';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import pngToIco from 'png-to-ico';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
// Read the logo SVG
const logoSvg = fs.readFileSync(path.join(__dirname, 'public/logo.svg'));
async function createIcons() {
try {
const pngSizes = [
{ size: 512, name: 'public/logo.png' },
{ size: 256, name: 'public/logo-256.png' },
{ size: 128, name: 'public/logo-128.png' },
{ size: 64, name: 'public/logo-64.png' },
{ size: 32, name: 'public/logo-32.png' },
{ size: 16, name: 'public/logo-16.png' }
];
for (const { size, name } of pngSizes) {
console.log(`Creating ${name} (${size}x${size})...`);
await sharp(logoSvg, { density: 300 })
.resize(size, size, { fit: 'contain', background: { r: 255, g: 255, b: 255, alpha: 0 } })
.png()
.toFile(path.join(__dirname, name));
}
console.log('Creating public/logo.ico...');
const icoBuffer = await pngToIco([
path.join(__dirname, 'public/logo-16.png'),
path.join(__dirname, 'public/logo-32.png'),
path.join(__dirname, 'public/logo-64.png'),
path.join(__dirname, 'public/logo-128.png'),
path.join(__dirname, 'public/logo-256.png')
]);
fs.writeFileSync(path.join(__dirname, 'public/logo.ico'), icoBuffer);
console.log('✓ All icons created successfully!');
} catch (error) {
console.error('✗ Error creating icons:', error);
process.exit(1);
}
}
createIcons();