https://github.com/dy/image-encode
Encode pixels data to PNG, GIF, BMP, TIF or JPG
https://github.com/dy/image-encode
Last synced: 9 months ago
JSON representation
Encode pixels data to PNG, GIF, BMP, TIF or JPG
- Host: GitHub
- URL: https://github.com/dy/image-encode
- Owner: dy
- Created: 2018-11-10T20:23:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-01-15T20:46:56.000Z (over 5 years ago)
- Last Synced: 2024-12-29T00:12:21.555Z (over 1 year ago)
- Language: JavaScript
- Size: 39.1 KB
- Stars: 24
- Watchers: 3
- Forks: 4
- Open Issues: 7
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# image-encode [](http://github.com/badges/stability-badges) [](https://travis-ci.org/dy/image-encode)
Encode image data to a container: PNG, GIF, BMP, JPEG or TIFF. Uses set of encoders in node and Canvas2D in browser.
## Usage
[](https://npmjs.org/package/image-encode/)
```js
let encode = require('image-encode')
// create a file with chess pattern
fs.writeFileSync(
'out.png',
Buffer.from(encode([0,0,0,255, 255,255,255,255, 255,255,255,255, 0,0,0,255], [2, 2], 'png'))
)
```
## API
### `let data = encode(pixels, shape?, format|options?)`
Takes input `pixels` Array/TypedArray/ArrayBuffer/Buffer/ImageData, returns an ArrayBuffer with encoded `data` in target `format`, one of `png`, `gif`, `tif`, `bmp`, `jpg`.
`options` can provide:
* `format` or `type`, if not specified as a separate argument.
* `shape` or `width`/`height`, if not defined by `pixels` or as a separate argument.
* `quality` for JPG encoder.
* `colors` for palette size in GIF encoder.
* any other meta fields for encoders.
## See also
* [squoosh.app](https://github.com/GoogleChromeLabs/squoosh) − best in class image compressing app.
* [image-decode](https://ghub.io/image-decode) − decode image data from a format.
* [image-equal](https://ghub.io/image-equal) − image data comparing tool.
* [image-pixels](https://ghub.io/image-pixels) − load or save pixel data from/to any source.
* [image-save](https://ghub.io/image-save) − save image pixels data to a target.
* [image-type](https://ghub.io/image-type) − detect input image data type.
## Footer
© 2018 Dmitry Yv. MIT License.