import { writeFileSync } from 'fs'; import { deflateSync } from 'zlib'; function makePng(size, r, g, b) { const crcTable = new Uint32Array(256); for (let n = 0; n < 256; n++) { let c = n; for (let k = 0; k < 8; k++) { c = (c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1); } crcTable[n] = c; } function crc32(buf) { let c = ~0; for (let i = 0; i < buf.length; i++) { c = crcTable[(c ^ buf[i]) & 0xFF] ^ (c >>> 8); } return ~c >>> 0; } function writeChunk(type, data) { const len = Buffer.alloc(4); len.writeUInt32BE(data.length, 0); const typeBuf = Buffer.from(type, 'ascii'); const crc = Buffer.alloc(4); crc.writeUInt32BE(crc32(Buffer.concat([typeBuf, data])), 0); return Buffer.concat([len, typeBuf, data, crc]); } const ihdrData = Buffer.from([ 0x00, 0x00, 0x00, size, 0x00, 0x00, 0x00, size, 0x08, 0x02, 0x00, 0x00, 0x00, ]); const ihdrChunk = writeChunk('IHDR', ihdrData); const raw = []; for (let y = 0; y < size; y++) { raw.push(0); for (let x = 0; x < size; x++) { raw.push(r, g, b, 255); } } const rawBuf = Buffer.from(raw); const compressed = deflateSync(rawBuf); const idatChunk = writeChunk('IDAT', compressed); const iendChunk = writeChunk('IEND', Buffer.alloc(0)); const sig = Buffer.from([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]); return Buffer.concat([sig, ihdrChunk, idatChunk, iendChunk]); } writeFileSync('icons/icon16.png', makePng(16, 99, 102, 241)); writeFileSync('icons/icon48.png', makePng(48, 99, 102, 241)); writeFileSync('icons/icon128.png', makePng(128, 99, 102, 241)); console.log('Icons created');