Output image data to a file, console, canvas, array or buffer
npm install image-outputjs
var output = require('image-output')
// create chess pattern png from raw pixels data
output({
data: [0,0,0,1, 1,1,1,1, 1,1,1,1, 0,0,0,1],
width: 2,
height: 2
}, 'chess.png')
`
API
$3
Output pixel data source to a destination based on options. Undefined destination displays image to console/stdout. The operation is done in sync fashion. destination and options may come in the opposite order for conveniency.
`js
output([0,1,1,0], [2,2,1], 'a.png')
`
#### source
Shoud be an actual image data container, one of:
* _Canvas_, _Context2D_, _WebGLContext_
* _ImageData_ or _Object_ {data: Uint8Array, width, height}
* DataURL or base64 string
* _Image_, _Video_, _ImageBitmap_ with resolved data
* _Array_, _Array_ of _Arrays_, _Uint8Array_, _FloatArray_ with raw pixels
* _ArrayBuffer_, _Buffer_
* _Ndarray_
Handy for that purpose is image-pixels:
`js
var pixels = require('image-pixels')
output(await pixels('image.png'), 'image-copy.png')
`
#### destination
Can be any image output destination:
Type | Meaning
---|---
_String_ | File to create or path, in node. If includes extension, mimeType is detected from it.
_Canvas2D_, _Context2D_ | Render pixel data into a canvas. Canvas is resized to fit the image data. To avoid resizing, use options.clip property.
document, _Element_ | Create a canvas with diff data in document or element.
console | Display image to console in browser or to terminal in node.
_Array_ / _FloatArray_ | Write pixel data normalized to [0..1] range to a float-enabled array.
_UintArray_ | Put pixel data to any unsigned int array.
_Buffer_ / _ArrayBuffer_ | Put pixel data into a buffer, possibly encoded into target format by options.type.
_Ndarray_ | Write pixel data into an ndarray.
_ImageData_ | Put data into _ImageData_ instance, browser only.
_Object_ | Create data, width and height properties on an object.
_Function_ | Call a function with _ImageData_ as argument.
_Stream_ | Send data to stream, eg. process.stdout.
_WebStream_ | TODO. Send data to stream, eg. process.stdout.
#### options
Property | Meaning
---|---
type / mime | Encode into target type, by default detected from file extension. By default image/png.
quality | Defines encoding quality, 0..1, optional. By default 1.
...rest | Rest of options is passed to encoder.
Customize color palette in terminal
You can choose color palette with flags or environment variable FORCE_COLOR=0123
`
node ./script.js --no-color
node ./script.js --color
node ./script.js --color=256
node ./script.js --color=16m
``