Files
svelte-mud/generate-icons.js

39 lines
1.0 KiB
JavaScript
Raw Normal View History

2025-04-21 14:12:36 +02:00
// Script to convert SVG to various PNG sizes for PWA icons
// Requires: npm install sharp
// Usage: node generate-icons.js
const fs = require('fs');
const path = require('path');
const sharp = require('sharp');
// Define icon sizes needed
const sizes = [72, 96, 128, 144, 152, 192, 384, 512];
// Input SVG file
const svgFile = path.join(__dirname, 'static/icons/icon-512x512.svg');
// Read the SVG file
fs.readFile(svgFile, (err, data) => {
if (err) throw err;
// Convert to each size
sizes.forEach(size => {
const outputFile = path.join(__dirname, `static/icons/icon-${size}x${size}.png`);
sharp(data)
.resize(size, size)
.png()
.toFile(outputFile)
.then(() => {
console.log(`Created icon: ${outputFile}`);
})
.catch(err => {
console.error(`Error creating ${outputFile}:`, err);
});
});
});
console.log('To use this script, first install the required dependency:');
console.log('npm install sharp');
console.log('Then run: node generate-icons.js');