PNG2ICOjs is a simple and small (1.31KB minified) Javascript ES6 module that convert PNG files into ICO file. It should work on any Javascript environment including browsers.
Was it helpful for you? Please consider a donation ❤️ PayPal.
Right now I haven't deployed the library to any CDN yet. Please grab the script files in Release page. It is available in TypeScript and Javascript file.
To use the module, simply import it in your script:
import{PngIcoConverter}from"../src/png2icojs.js";// ...constinputs=[...files].map(file=>({png: file}));// Result is a BlobconstresultBlob1=awaitconverter.convertToBlobAsync(inputs);// Default mime type is image/x-iconconstresultBlob2=awaitconverter.convertToBlobAsync(inputs,"image/your-own-mime");// Result is an Uint8ArrayconstresultArr=awaitconverter.convertAsync(inputs);You can check the demo at the Demo page.
The API exposes the PngIcoConverter class with many protected function so you can override them to your need.
PngIcoConverter exposes publicly the following methods:
async convertToBlobAsync(inputs: IConvertInputItem[], mime = IcoMime): Promise<Blob>;
Convert PNG files into a ICO Blob with optional mime type. Default: image/x-icon.
async convertAsync(inputs: IConvertInputItem[]): Promise<Uint8Array>;
Convert PNG files into a Uint8Array.
IConvertInputItem has the following properties:
png: the PNG file. Can beBloborArrayBuffer.bpp(optional, default 0): Bits per pixel. For the header of the ICO image. In my experiments, most apps just ignore this value altogether and use the value from PNG image.ignoreSize(optional, default false): Due to thesizebyte of ICO only has 1 byte, the maximum size of icons are 256px. However I have attemped to make an icon with 512px icon and it works so far. The library still throw anErrorif your image size is more than 256px. Set this totrueto ignore it.