thinking-model-client / scripts /generate-icons.js
moelove's picture
PWA
c1944cf
raw
history blame
1.17 kB
// This script can be used to generate different sized icons from the SVG source
// You would need to install sharp: npm install sharp
// Then run: node scripts/generate-icons.js
const fs = require('fs');
const path = require('path');
const sharp = require('sharp');
const sizes = [72, 96, 128, 144, 152, 192, 384, 512];
const svgPath = path.join(__dirname, '../public/icons/icon-512x512.svg');
const outputDir = path.join(__dirname, '../public/icons');
async function generateIcons() {
try {
// Make sure the output directory exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
// Read the SVG file
const svgBuffer = fs.readFileSync(svgPath);
// Generate each size
for (const size of sizes) {
const outputPath = path.join(outputDir, `icon-${size}x${size}.png`);
await sharp(svgBuffer)
.resize(size, size)
.png()
.toFile(outputPath);
console.log(`Generated: ${outputPath}`);
}
console.log('All icons generated successfully!');
} catch (error) {
console.error('Error generating icons:', error);
}
}
generateIcons();