Jarch09 / ts-png-to-ico

Convert PNG to ICO in memory
MIT License
2 stars 0 forks source link

ts-png-to-ico

Convert PNG to ICO in memory.

This repo serves as a replacement for https://github.com/kevva/to-ico.

Why this repo?

There are a bunch of other PNG to ICO tools and repos out there. Many of them, however, are woefully out of date and unmaintained. This is a modern TypeScript version with updated dependencies and full test coverage.

Install

yarn add ts-png-to-ico

Utilization

Basic

import fs from 'fs';
import pngToIco from 'ts-png-to-ico';

const pngBuf = fs.readFileSync('some-image.png');
const icoBuf = await pngToIco(pngBuf);

const icoFile = fs.writeFileSync('app.ico', icoBuf);

Multiple Images

import fs from 'fs';
import pngToIco from 'ts-png-to-ico';

const pngBuf = fs.readFileSync('some-image.png');
const smallerPngBuf = fs.readFileSync('smaller-image.png');
const icoBuf = await pngToIco([pngBuf, smallerPngBuf]);

const icoFile = fs.writeFileSync('app.ico', icoBuf);

Options

import fs from 'fs';
import pngToIco from 'ts-png-to-ico';

const icoOptions = {
  resize: true,
  sizes: [20, 25, 100, 200],
}

const pngBuf = fs.readFileSync('some-image.png');
const icoBuf = await pngToIco(pngBuf, icoOptions);

const icoFile = fs.writeFileSync('app.ico', icoBuf);

License

MIT License