icojs
parse ico file
Last updated 3 months ago by egy186 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install icojs 
SYNC missed versions from official npm registry.

icojs

npm CI Coverage Status codebeat badge

A JavaScript library to use ICO. Works on both Node.js and the browser.

Install

npm install icojs

Node.js:

import { isICO, parseICO } from 'icojs';

Browser:

import { isICO, parseICO } from 'icojs/browser';

or

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

To fully use this library, browsers must support JavaScript typed arrays, Canvas API and Promise. Chrome, Edge 12, Firefox and Safari 9 support these functions.

Example

Node.js:

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

const buffer = await readFile('favicon.ico');
const images = await parseICO(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.getElementById('input-file').addEventListener('change', evt => {
    // use FileReader for converting File object to ArrayBuffer object
    var reader = new FileReader();
    reader.onload = async e => {
      const images = await ICO.parseICO(e.target.result);
      // logs images
      console.dir(images);
    };
    reader.readAsArrayBuffer(evt.target.files[0]);
  }, false);
</script>

Demo

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

API

ICO

isICO(source) ⇒ boolean

Check the ArrayBuffer is valid ICO.

Kind: global method of ICO
Returns: boolean - True if arg is ICO.

Param Type Description
source ArrayBuffer | Buffer ICO file data.

parseICO(buffer, [mime]) ⇒ Promise.<Array.<ParsedImage>>

Parse ICO and return some images.

Kind: global method of ICO
Returns: Promise.<Array.<ParsedImage>> - Resolves to an array of ParsedImage.

Param Type Default Description
buffer ArrayBuffer | Buffer ICO file data.
[mime] string "image/png" MIME type for output.

Typedefs

ParsedImage : object

Kind: global typedef
Properties

Name Type Description
width number Image width.
height number Image height.
bpp number Image color depth as bits per pixel.
buffer ArrayBuffer Image buffer.

License

MIT license

Current Tags

  • 0.19.4                                ...           latest (3 months ago)

41 Versions

  • 0.19.4                                ...           3 months ago
  • 0.19.3                                ...           a year ago
  • 0.19.2                                ...           a year ago
  • 0.19.1                                ...           a year ago
  • 0.19.0                                ...           a year ago
  • 0.18.0                                ...           a year ago
  • 0.17.1                                ...           2 years ago
  • 0.17.0                                ...           3 years ago
  • 0.16.1                                ...           4 years ago
  • 0.16.0                                ...           4 years ago
  • 0.15.1                                ...           4 years ago
  • 0.15.0                                ...           4 years ago
  • 0.14.0                                ...           5 years ago
  • 0.13.1                                ...           5 years ago
  • 0.13.0                                ...           5 years ago
  • 0.12.3                                ...           6 years ago
  • 0.12.2                                ...           6 years ago
  • 0.12.1                                ...           6 years ago
  • 0.12.0                                ...           7 years ago
  • 0.11.0                                ...           7 years ago
  • 0.10.1                                ...           7 years ago
  • 0.10.0                                ...           7 years ago
  • 0.9.1                                ...           7 years ago
  • 0.9.0                                ...           7 years ago
  • 0.8.1                                ...           7 years ago
  • 0.8.0                                ...           7 years ago
  • 0.7.2                                ...           8 years ago
  • 0.7.1                                ...           8 years ago
  • 0.7.0                                ...           8 years ago
  • 0.6.0                                ...           8 years ago
  • 0.5.0                                ...           8 years ago
  • 0.5.0-alpha                                ...           8 years ago
  • 0.4.1                                ...           8 years ago
  • 0.4.0                                ...           9 years ago
  • 0.4.0-alpha.1                                ...           9 years ago
  • 0.4.0-alpha                                ...           9 years ago
  • 0.3.0                                ...           9 years ago
  • 0.3.0-alpha.3                                ...           9 years ago
  • 0.3.0-alpha.1                                ...           9 years ago
  • 0.3.0-alpha                                ...           9 years ago
  • 0.2.0                                ...           10 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dev Dependencies (22)
Dependents (1)

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