image-encode
v1.3.1
Published
Decode image data into any format: gif, jpeg, png, tiff or bmp
Downloads
19,289
Readme
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
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
ortype
, if not specified as a separate argument.shape
orwidth
/height
, if not defined bypixels
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 − best in class image compressing app.
- image-decode − decode image data from a format.
- image-equal − image data comparing tool.
- image-pixels − load or save pixel data from/to any source.
- image-save − save image pixels data to a target.
- image-type − detect input image data type.
Footer
© 2018 Dmitry Yv. MIT License.