0.19.4 • Published 4 months ago

icojs v0.19.4

Weekly downloads
797
License
MIT
Repository
github
Last release
4 months ago

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.

ParamTypeDescription
sourceArrayBuffer | BufferICO 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.

ParamTypeDefaultDescription
bufferArrayBuffer | BufferICO file data.
mimestring"image/png"MIME type for output.

Typedefs

ParsedImage : object

Kind: global typedef
Properties

NameTypeDescription
widthnumberImage width.
heightnumberImage height.
bppnumberImage color depth as bits per pixel.
bufferArrayBufferImage buffer.

License

MIT license

0.19.4

4 months ago

0.19.3

1 year ago

0.19.2

1 year ago

0.19.0

1 year ago

0.19.1

1 year ago

0.18.0

1 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

6 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