https://github.com/LinusU/cwasm-lodepng
PNG decoding for Node.js, using LodePNG compiled to WebAssembly
https://github.com/LinusU/cwasm-lodepng
Last synced: about 1 year ago
JSON representation
PNG decoding for Node.js, using LodePNG compiled to WebAssembly
- Host: GitHub
- URL: https://github.com/LinusU/cwasm-lodepng
- Owner: LinusU
- Created: 2018-10-13T13:13:04.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-09-26T20:38:48.000Z (over 3 years ago)
- Last Synced: 2025-04-15T16:49:30.868Z (about 1 year ago)
- Language: JavaScript
- Size: 68.4 KB
- Stars: 37
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# LodePNG
PNG decoding/encoding for Node.js, using [LodePNG][LodePNG] compiled to [WebAssembly][WebAssembly].
[LodePNG]: https://lodev.org/lodepng/
[WebAssembly]: https://webassembly.org
## Installation
```sh
npm install --save @cwasm/lodepng
```
## Usage
```js
const fs = require('fs')
const lodepng = require('@cwasm/lodepng')
const source = fs.readFileSync('image.png')
const image = lodepng.decode(source)
console.log(image)
// { width: 128,
// height: 128,
// data:
// Uint8ClampedArray [ ... ] }
const data = lodepng.encode(image)
console.log(data)
// Uint8Array [ 137, 80, 78, 71, ... ]
```
## API
### `decode(source)`
- `source` ([`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), required) - The PNG data
- returns [`ImageData`](https://developer.mozilla.org/en-US/docs/Web/API/ImageData) - Decoded width, height and pixel data
### `encode(source)`
- `source` (`ImageLike`, required) - The image data
- returns [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) - Encoded data