You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.4 KiB
JavaScript

const sharp = require('sharp');
const fs = require('fs');
const path = require('path');
// SVG content for the favicon
const svgContent = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<!-- Crystal Ball Base -->
<ellipse cx="256" cy="420" rx="120" ry="40" fill="#1e40af"/>
<!-- Crystal Ball -->
<circle cx="256" cy="256" r="180" fill="#3b82f6" opacity="0.9"/>
<!-- Crystal Ball Shine -->
<ellipse cx="220" cy="200" rx="60" ry="80" fill="#60a5fa" opacity="0.6"/>
<!-- Stock Chart Line -->
<path d="M 150 280 L 180 260 L 210 270 L 240 240 L 270 250 L 300 220 L 330 230 L 360 200"
stroke="white" stroke-width="6" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
<!-- Chart Points -->
<circle cx="150" cy="280" r="8" fill="white"/>
<circle cx="180" cy="260" r="8" fill="white"/>
<circle cx="210" cy="270" r="8" fill="white"/>
<circle cx="240" cy="240" r="8" fill="white"/>
<circle cx="270" cy="250" r="8" fill="white"/>
<circle cx="300" cy="220" r="8" fill="white"/>
<circle cx="330" cy="230" r="8" fill="white"/>
<circle cx="360" cy="200" r="8" fill="white"/>
</svg>`;
const publicDir = path.join(__dirname, '..', 'public');
// Ensure public directory exists
if (!fs.existsSync(publicDir)) {
fs.mkdirSync(publicDir, { recursive: true });
}
async function generateIcons() {
try {
// Save SVG file
fs.writeFileSync(path.join(publicDir, 'favicon.svg'), svgContent);
console.log('✅ Generated favicon.svg');
// Generate PNG icons in various sizes
const sizes = [
{ size: 16, name: 'favicon-16x16.png' },
{ size: 32, name: 'favicon-32x32.png' },
{ size: 192, name: 'icon-192.png' },
{ size: 512, name: 'icon-512.png' },
{ size: 180, name: 'apple-touch-icon.png' }
];
for (const { size, name } of sizes) {
await sharp(Buffer.from(svgContent))
.resize(size, size)
.png()
.toFile(path.join(publicDir, name));
console.log(`✅ Generated ${name}`);
}
// Generate favicon.ico (multi-resolution)
await sharp(Buffer.from(svgContent))
.resize(32, 32)
.png()
.toFile(path.join(publicDir, 'favicon.ico'));
console.log('✅ Generated favicon.ico');
console.log('\n🎉 All icons generated successfully!');
} catch (error) {
console.error('Error generating icons:', error);
process.exit(1);
}
}
generateIcons();