ico-codec
v1.0.0
Published
Zero-dependency ICO encoder. Combine PNG images into a valid .ico file. Works in browser and Node.js.
Maintainers
Readme
ico-codec
Zero-dependency ICO encoder. Combine PNG images into a valid .ico file.
Works in browser and Node.js.
Install
npm install ico-codecUsage
import { encodeIco } from "ico-codec";
// Each entry is a PNG buffer at a specific icon size
const ico = encodeIco([
{ size: 16, data: png16Buffer },
{ size: 32, data: png32Buffer },
{ size: 48, data: png48Buffer },
]);
// ico is a Uint8Array — write it to a file, create a Blob, etc.
const blob = new Blob([ico], { type: "image/x-icon" });A convenience encodeIcoBlob() is also exported for browser use:
import { encodeIcoBlob } from "ico-codec";
const blob = encodeIcoBlob([
{ size: 16, data: png16Buffer },
{ size: 32, data: png32Buffer },
]);
// blob is a Blob with type "image/x-icon"API
encodeIco(images: IcoImage[]): Uint8Array
Encodes an array of PNG images into a single ICO file. Returns a Uint8Array.
encodeIcoBlob(images: IcoImage[]): Blob
Same as encodeIco() but returns a Blob with MIME type image/x-icon.
IcoImage
interface IcoImage {
size: number; // Icon dimension in pixels (e.g. 16, 32, 48, 256)
data: ArrayBuffer | Uint8Array; // Raw PNG file data
}How it works
The ICO format is a container that bundles multiple PNG images at different resolutions into a single file. This encoder writes the ICO header, one directory entry per image, then concatenates the raw PNG data. No image processing or re-encoding — your PNGs are embedded as-is.
License
MIT — extracted from LeanImg.
