42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
// Script to convert SVG to various PNG sizes for PWA icons
|
|
// Requires: npm install sharp
|
|
// Usage: node generate-icons.js
|
|
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import sharp from 'sharp';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
|
// 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');
|