38 lines
1.7 KiB
JavaScript
Executable File
38 lines
1.7 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
'use strict'
|
|
// Build a multi-resolution icons/icon.ico from the PNG set (no dependencies).
|
|
// A modern .ico is just a small directory header followed by the PNG files embedded
|
|
// verbatim (Windows Vista+ supports PNG-compressed icon entries). Regenerate after
|
|
// changing the source art: `node scripts/gen-ico.js`.
|
|
const fs = require('fs')
|
|
const path = require('path')
|
|
|
|
const iconsDir = path.join(__dirname, '..', 'icons')
|
|
const sizes = [16, 32, 48, 64, 128, 256] // .ico max is 256; taskbar picks the best fit
|
|
const imgs = sizes.map(s => ({ size: s, data: fs.readFileSync(path.join(iconsDir, `${s}x${s}.png`)) }))
|
|
|
|
const header = Buffer.alloc(6)
|
|
header.writeUInt16LE(0, 0) // reserved
|
|
header.writeUInt16LE(1, 2) // type: 1 = icon
|
|
header.writeUInt16LE(imgs.length, 4) // image count
|
|
|
|
const entries = []
|
|
let offset = 6 + imgs.length * 16 // pixel data starts after header + all dir entries
|
|
for (const { size, data } of imgs) {
|
|
const e = Buffer.alloc(16)
|
|
e.writeUInt8(size >= 256 ? 0 : size, 0) // width (0 means 256)
|
|
e.writeUInt8(size >= 256 ? 0 : size, 1) // height (0 means 256)
|
|
e.writeUInt8(0, 2) // palette color count
|
|
e.writeUInt8(0, 3) // reserved
|
|
e.writeUInt16LE(1, 4) // color planes
|
|
e.writeUInt16LE(32, 6) // bits per pixel
|
|
e.writeUInt32LE(data.length, 8) // size of PNG data
|
|
e.writeUInt32LE(offset, 12) // offset to PNG data
|
|
entries.push(e)
|
|
offset += data.length
|
|
}
|
|
|
|
const ico = Buffer.concat([header, ...entries, ...imgs.map(i => i.data)])
|
|
fs.writeFileSync(path.join(iconsDir, 'icon.ico'), ico)
|
|
console.log(`[gen-ico] wrote icons/icon.ico — ${imgs.length} sizes (${sizes.join(', ')}), ${ico.length} bytes`)
|