Output image data to a destination: file, canvas, console, stdout, ImageData etc.
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')
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.
output([0,1,1,0], [2,2,1], 'a.png')
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
:
var pixels = require('image-pixels')
output(await pixels('image.png'), 'image-copy.png')
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 |
Create a canvas with diff data in document or element. |
console |
Display image in console in browser or 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 the function ImageData argument. |
Stream | Send data to stream, eg. process.stdout . |
Property | Meaning |
---|---|
clip |
Defile clipping area rectangle from the initial data to save. Can be |
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. |
- image-equal − compare if two images are equal.
- image-pixels − load image data from any source.
- image-encode − encode image data into one of the target formats.
- save-pixels − output ndarray with image pixels to a file.
- terminal-image − print image to a terminal.
© 2018 Dmitry Yv. MIT License.