icojs-min
v0.5.0
Published
parse ico file
Downloads
2
Readme
icojs
A JavaScript library to use ICO. Work on both Node.js and 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 arrayBuffer = new Uint8Array(fs.readFileSync('favicon.ico')).buffer;
ICO.parse(arrayBuffer, '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
Documentation
- ICO
- .parse(buffer, [mime]) ⇒ Promise.<Array.<Object>>
- .isICO(buffer) ⇒ Boolean
- .noConflict() ⇒ ICO
ICO.parse(buffer, [mime]) ⇒ Promise.<Array.<Object>>
Parse ICO and return some images.
Kind: static method of ICO
Returns: Promise.<Array.<Object>> - Resolves to array of parsed ICO.
width
Number - Image width.height
Number - Image height.bit
Number - Image bit depth.buffer
ArrayBuffer - Image buffer.
| Param | Type | Default | Description | | --- | --- | --- | --- | | buffer | ArrayBuffer | | The ArrayBuffer object contain the TypedArray of a ICO file. | | [mime] | String | image/png | MIME type for output. |
ICO.isICO(buffer) ⇒ Boolean
Check the ArrayBuffer is valid ICO.
Kind: static method of ICO
Returns: Boolean - True if arg is ICO.
| Param | Type | Description | | --- | --- | --- | | buffer | ArrayBuffer | The ArrayBuffer object contain the TypedArray of a ICO file. |
ICO.noConflict() ⇒ ICO
No conflict.
Kind: static method of ICO
Returns: ICO - ICO
Object.
License
MIT license