|
| 1 | +#!/usr/bin/env node |
| 2 | +import sharp from 'sharp'; |
| 3 | +import { readFileSync, writeFileSync } from 'fs'; |
| 4 | +import { join, dirname } from 'path'; |
| 5 | +import { fileURLToPath } from 'url'; |
| 6 | + |
| 7 | +const __filename = fileURLToPath(import.meta.url); |
| 8 | +const __dirname = dirname(__filename); |
| 9 | + |
| 10 | +// ICO format header writer |
| 11 | +function createIco(pngs) { |
| 12 | + // ICO header |
| 13 | + const header = Buffer.alloc(6); |
| 14 | + header.writeUInt16LE(0, 0); // Reserved |
| 15 | + header.writeUInt16LE(1, 2); // Type: ICO |
| 16 | + header.writeUInt16LE(pngs.length, 4); // Number of images |
| 17 | + |
| 18 | + // Directory entries |
| 19 | + const dirEntries = Buffer.alloc(16 * pngs.length); |
| 20 | + let offset = 6 + (16 * pngs.length); |
| 21 | + |
| 22 | + pngs.forEach((png, i) => { |
| 23 | + const entry = dirEntries.slice(i * 16, (i + 1) * 16); |
| 24 | + entry.writeUInt8(png.size, 0); // Width |
| 25 | + entry.writeUInt8(png.size, 1); // Height |
| 26 | + entry.writeUInt8(0, 2); // Color palette |
| 27 | + entry.writeUInt8(0, 3); // Reserved |
| 28 | + entry.writeUInt16LE(1, 4); // Color planes |
| 29 | + entry.writeUInt16LE(32, 6); // Bits per pixel |
| 30 | + entry.writeUInt32LE(png.data.length, 8); // Image size |
| 31 | + entry.writeUInt32LE(offset, 12); // Image offset |
| 32 | + offset += png.data.length; |
| 33 | + }); |
| 34 | + |
| 35 | + return Buffer.concat([header, dirEntries, ...pngs.map(p => p.data)]); |
| 36 | +} |
| 37 | + |
| 38 | +async function main() { |
| 39 | + const sizes = [256, 128, 64, 48, 32, 16]; |
| 40 | + const pngs = []; |
| 41 | + |
| 42 | + console.log('Creating ICO file from thunder icon...'); |
| 43 | + |
| 44 | + const svgBuffer = readFileSync(join(__dirname, 'icon.svg')); |
| 45 | + |
| 46 | + for (const size of sizes) { |
| 47 | + const pngData = await sharp(svgBuffer) |
| 48 | + .resize(size, size) |
| 49 | + .png() |
| 50 | + .toBuffer(); |
| 51 | + |
| 52 | + pngs.push({ size: size === 256 ? 0 : size, data: pngData }); |
| 53 | + console.log(`✓ ${size}x${size}`); |
| 54 | + } |
| 55 | + |
| 56 | + const ico = createIco(pngs); |
| 57 | + writeFileSync(join(__dirname, 'src-tauri', 'icons', 'icon.ico'), ico); |
| 58 | + console.log('✅ icon.ico created'); |
| 59 | +} |
| 60 | + |
| 61 | +main().catch(console.error); |
0 commit comments