icojs
Decode and encode ICO files
Last updated 3 months ago by GitHub Actions .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install icojs 
SYNC missed versions from official npm registry.

icojs

NPM Version CI Coverage Status

A JavaScript library for decoding and encoding ICO files. Works in both Node.js and the browser.

Install

npm install icojs
import { decodeIco, encodeIco, isIco } from 'icojs';

A UMD bundle is also available for browsers.

<script src="node_modules/icojs/dist/ico.js"></script>

Demo

Example

Decoding

Node.js:

import { readFile, writeFile } from 'node:fs/promises';
import { decodeIco } from 'icojs';

const buffer = await readFile('favicon.ico');
const images = await decodeIco(buffer, 'image/png');
// save as png files
images.forEach(image => {
  const file = `${image.width}x${image.height}-${image.bpp}bit.png`;
  const data = Buffer.from(image.buffer);
  writeFile(file, data);
});

Browser:

<input type="file" id="input-file" />
<script>
  document.querySelector('#input-file').addEventListener('change', async evt => {
    const file = evt.target.files[0];
    const buffer = await file.arrayBuffer();
    const images = await ICO.decodeIco(buffer);
    // logs images
    console.dir(images);
  });
</script>

Encoding

Node.js:

import { readFile, writeFile } from 'node:fs/promises';
import { encodeIco } from 'icojs';

const buffer1 = await readFile('16x16.png');
const buffer2 = await readFile('32x32.png');
const ico = await encodeIco([
  { buffer: buffer1 },
  { buffer: buffer2 }
]);
// save as a ico file
writeFile('favicon.ico', Buffer.from(ico));

Browser:

<input type="file" id="input-file" multiple />
<script>
  document.querySelector('#input-file').addEventListener('change', async evt => {
    const files = Array.from(evt.target.files);
    const iconList = await Promise.all(files.map(async file => {
      const buffer = await file.arrayBuffer();
      return { buffer };
    }));
    const ico = await ICO.encodeIco(iconList);
    // logs ico
    console.dir(ico);
  });
</script>

API Documentation

https://egy186.github.io/icojs/

Current Tags

  • 1.0.1                                ...           latest (3 months ago)

52 Versions

  • 1.0.1                                ...           3 months ago
  • 1.0.0                                ...           6 months ago
  • 0.23.0                                ...           7 months ago
  • 0.22.1                                ...           7 months ago
  • 0.22.0                                ...           7 months ago
  • 0.21.1                                ...           8 months ago
  • 0.21.0                                ...           8 months ago
  • 0.20.2                                ...           8 months ago
  • 0.20.1                                ...           a year ago
  • 0.20.0                                ...           a year ago
  • 0.19.5                                ...           2 years ago
  • 0.19.4                                ...           2 years ago
  • 0.19.3                                ...           3 years ago
  • 0.19.2                                ...           3 years ago
  • 0.19.1                                ...           3 years ago
  • 0.19.0                                ...           3 years ago
  • 0.18.0                                ...           3 years ago
  • 0.17.1                                ...           4 years ago
  • 0.17.0                                ...           5 years ago
  • 0.16.1                                ...           6 years ago
  • 0.16.0                                ...           6 years ago
  • 0.15.1                                ...           6 years ago
  • 0.15.0                                ...           6 years ago
  • 0.14.0                                ...           7 years ago
  • 0.13.1                                ...           7 years ago
  • 0.13.0                                ...           7 years ago
  • 0.12.3                                ...           8 years ago
  • 0.12.2                                ...           8 years ago
  • 0.12.1                                ...           8 years ago
  • 0.12.0                                ...           9 years ago
  • 0.11.0                                ...           9 years ago
  • 0.10.1                                ...           9 years ago
  • 0.10.0                                ...           9 years ago
  • 0.9.1                                ...           9 years ago
  • 0.9.0                                ...           9 years ago
  • 0.8.1                                ...           9 years ago
  • 0.8.0                                ...           9 years ago
  • 0.7.2                                ...           10 years ago
  • 0.7.1                                ...           10 years ago
  • 0.7.0                                ...           10 years ago
  • 0.6.0                                ...           10 years ago
  • 0.5.0                                ...           10 years ago
  • 0.5.0-alpha                                ...           10 years ago
  • 0.4.1                                ...           10 years ago
  • 0.4.0                                ...           11 years ago
  • 0.4.0-alpha.1                                ...           11 years ago
  • 0.4.0-alpha                                ...           11 years ago
  • 0.3.0                                ...           11 years ago
  • 0.3.0-alpha.3                                ...           11 years ago
  • 0.3.0-alpha.1                                ...           11 years ago
  • 0.3.0-alpha                                ...           11 years ago
  • 0.2.0                                ...           12 years ago
Maintainers (1)
Downloads
Total 95
Today 0
This Week 18
This Month 88
Last Day 0
Last Week 11
Last Month 0
Dependencies (5)
Dev Dependencies (16)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE