https://github.com/kettek/ico-endec-js
WIP ICO encoder and decoder
https://github.com/kettek/ico-endec-js
cur decoder encoder ico icon javascript library nodejs
Last synced: 6 months ago
JSON representation
WIP ICO encoder and decoder
- Host: GitHub
- URL: https://github.com/kettek/ico-endec-js
- Owner: kettek
- License: mpl-2.0
- Created: 2020-03-29T21:56:52.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-10-26T01:09:01.000Z (over 1 year ago)
- Last Synced: 2024-12-02T00:20:23.715Z (6 months ago)
- Topics: cur, decoder, encoder, ico, icon, javascript, library, nodejs
- Language: JavaScript
- Size: 90.8 KB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ICO encoder & decoder
This JavaScript library provides an encoder and decoder for ICO and CUR files. Although this library can encode and decode both BMP and PNG images, BMP endec does not provide bitmasking support, and as such, will not work with some icons. However, PNG support is widespread and has become a more defacto standard for application icons, so this problem is largely moot -- but it still would be nice to have.## Encoding
### icoEndec.encode([Buffer||ArrayBuffer])
The encode function takes an array of ArrayBuffers or Buffers that contain BMP or PNG data. It returns a Buffer containing the binary data of the ICO file.#### Example
```
const icoEndec = require('ico-endec')
const fsPromises = require('fs').promises;(async () => {
let icoBuffer = icoEndec.encode([
await fsPromises.readFile('myIcon-16x16.png'),
await fsPromises.readFile('myIcon-32x32.png'),
await fsPromises.readFile('myIcon-64x64.png')
])
await fsPromises.writeFile('myIcon.ico', icoBuffer)
})()
```## Decoding
### icoEndec.decode(Buffer)
The decode function takes a Buffer or an ArrayBuffer that holds the binary data of an ICO file. It returns an array of [IconEntries](#iconentry).
#### Example
```
const icoEndec = require('ico-endec')
const fsPromises = require('fs').promises;(async () => {
let icons = icoEndec.decode(await fsPromises.readFile('myIcon.ico'))
icons.forEach((icon, index) => {
fsPromises.writeFile(`myIcon-${icon.width}x${icon.height}.${icon.imageType}`, icon.imageData)
})
})()
```## IconEntry
The IconEntry class stores various information about the given icon entry.| Accessor | Type | Description |
|-|-|-|
| width | Number | width of the image, maximum of 256
| height | Number | height of the image, maximum of 256
| colors | Number | number of colors
| colorPlanes | Number | color planes of an ICO image
| bitsPerPixel | Number | bits per pixel of an ICO image
| horizontalHotspot | Number | horizontal hotspot of a CUR image
| verticalHotspot | Number | vertical hotspot of a CUR image
| imageSize | Number | (interal) size of imageData's buffer
| imageOffset | Number | (interal) offset start of the image data
| imageType | String | 'png' or 'bmp'
| imageData | [Buffer](https://nodejs.org/api/buffer.html) | image data of the icon