Socket
Socket
Sign inDemoInstall

image-output

Package Overview
Dependencies
94
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    image-output

Output image data to a file, console, canvas, array or buffer


Version published
Weekly downloads
1.4K
decreased by-26.67%
Maintainers
1
Install size
3.68 MB
Created
Weekly downloads
 

Readme

Source

image-output Build Status unstable

Output image data to a destination: file, canvas, console, stdout, ImageData etc.

Usage

$ npm install image-output

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

output(source, destination?, shape|options?)

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')
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:

var pixels = require('image-pixels')
output(await pixels('image.png'), 'image-copy.png')
destination

Can be any image output destination:

TypeMeaning
StringFile to create or path, in node. If includes extension, mimeType is detected from it.
Canvas2D, Context2DRender pixel data into a canvas. Canvas is resized to fit the image data. To avoid resizing, use options.clip property.
document, ElementCreate a canvas with diff data in document or element.
consoleDisplay image to console in browser or to terminal in node.
Array / FloatArrayWrite pixel data normalized to [0..1] range to a float-enabled array.
UintArrayPut pixel data to any unsigned int array.
Buffer / ArrayBufferPut pixel data into a buffer, possibly encoded into target format by options.type.
NdarrayWrite pixel data into an ndarray.
ImageDataPut data into ImageData instance, browser only.
ObjectCreate data, width and height properties on an object.
FunctionCall a function with ImageData as argument.
StreamSend data to stream, eg. process.stdout.
WebStreamTODO. Send data to stream, eg. process.stdout.
options
PropertyMeaning
type / mimeEncode into target type, by default detected from file extension. By default image/png.
qualityDefines encoding quality, 0..1, optional. By default 1.
...restRest 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

Similar

License

© 2018 Dmitry Yv. MIT License.

Keywords

FAQs

Last updated on 03 Mar 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc