This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

parse-ico
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

parse-ico

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

NOTE: This package is a fork of parse-ico.

Install

npm install parse-ico

Node.js:

const ICO = require('parse-ico');

Browser:

const ICO = require('parse-ico/browser')

or

<script type="text/javascript" src="node_modules/parse-ico/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:

const fs = require('fs');
const ICO = require('parse-ico');

const buffer = fs.readFileSync('favicon.ico');
ICO.parse(buffer, 'image/png').then(images => {
  // save as png files
  images.forEach(image => {
    const file = `${image.width}x${image.height}-${image.bpp}bit.png`;
    const data = Buffer.from(image.buffer);
    fs.writeFileSync(file, data);
  });
});

Browser:

<input type="file" id="input-file" />
<script>
  document.getElementById('input-file').addEventListener('change', function (evt) {
    // use FileReader for converting File object to ArrayBuffer object
    var reader = new FileReader();
    reader.onload = function (e) {
      ICO.parse(e.target.result).then(function (images) {
        // logs images
        console.dir(images);
      })
    };
    reader.readAsArrayBuffer(evt.target.files[0]);
  }, false);
</script>

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.

parse(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

Readme

Keywords

Package Sidebar

Install

npm i parse-ico

Weekly Downloads

13

Version

1.0.2

License

MIT

Unpacked Size

53.7 kB

Total Files

18

Last publish

Collaborators

  • ironiumstudios