Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

icojs

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

icojs

parse ico file

  • 0.8.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.2K
increased by16.02%
Maintainers
1
Weekly downloads
 
Created
Source

icojs

npm Build Status dependencies Status Coverage Status codebeat badge

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

Install

npm install icojs

Node.js:

const ICO = require('icojs');

Browser:

const ICO = require('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:

const fs = require('fs');
const ICO = require('icojs');

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.bit}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>

Demo

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

API (Node.js)

ICO

isICO(buffer) ⇒ Boolean

Check the ArrayBuffer is valid ICO.

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

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

ParamTypeDefaultDescription
bufferArrayBuffer | BufferICO file data.
[mime]Stringimage/pngMIME type for output.

API (browser)

ICO

Kind: global class

ICO.parse(arrayBuffer, [mime]) ⇒ Promise.<Array.<ParsedImage>>

Parse ICO and return some images.

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

ParamTypeDefaultDescription
arrayBufferArrayBufferICO file data.
[mime]Stringimage/pngMIME type for output.

ICO.noConflict() ⇒ ICO

No conflict.

Kind: static method of ICO
Returns: ICO - ICO Object.

ICO.isICO(arrayBuffer) ⇒ Boolean

Check the ArrayBuffer is valid ICO.

Kind: static method of ICO
Returns: Boolean - True if arg is ICO.

ParamTypeDescription
arrayBufferArrayBufferICO file data.

Typedefs

ParsedImage : Object

Kind: global typedef
Properties

NameTypeDescription
widthNumberImage width.
heightNumberImage height.
bitNumberImage bit depth.
bufferArrayBufferImage buffer.

License

MIT license

Keywords

FAQs

Package last updated on 30 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc