import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import canvas from 'canvas';

const { createCanvas, loadImage } = canvas;

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

async function main() {
    const src = path.join(__dirname, 'public', 'image.png');
    const sizes = [16, 48, 128];

    const img = await loadImage(src);

    for (const size of sizes) {
        const c = createCanvas(size, size);
        const ctx = c.getContext('2d');
        ctx.drawImage(img, 0, 0, size, size);

        const buf = c.toBuffer('image/png');
        fs.writeFileSync(path.join(__dirname, 'icons', `icon${size}.png`), buf);
        console.log(`icon${size}.png created`);
    }
}

main().catch(console.error);
