Initial commit
This commit is contained in:
38
generate-icons.js
Normal file
38
generate-icons.js
Normal file
@@ -0,0 +1,38 @@
|
||||
// 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');
|
||||
Reference in New Issue
Block a user