Git Product home page Git Product logo

image-output's Introduction

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?, 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.

source

Shoud be an actual image data container, one of:

  • Canvas, Context2D, WebGLContext
  • ImageData
  • 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:

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.

options

Property Meaning
width, height Explicitly indicate input data shape (columns, rows), if input has no dimensions info.
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

Related

Similar

License

© 2018 Dmitry Iv. MIT License.

image-output's People

Contributors

dy avatar freaktechnik avatar lusori0 avatar munrocket avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

image-output's Issues

Can't resolve 'weak-map'

Hello,
thanks for your image-* modules.
I am using image-output indirectly, through image-equal, which requires it.
I get an error :

ERROR in ./node_modules/image-output/console-browser.js
Module not found: Error: Can't resolve 'weak-map' in '.../node_modules/image-output'
 @ ./node_modules/image-output/console-browser.js 5:14-33
 @ ./node_modules/image-output/index.js
 @ ./node_modules/image-equal/index.js

Indeed, in console-browser.js there is a require('weak-map') but no such dependency in package.json.

image-output version 2.3.1 (from image-equal version 4.3.0).

Sync API

Seems that DOM asyncs are the only blocker for sync API, the rest is well-done with async

saveFile.sync is not a function

When using image.output with image-pixels data and a string path to write to, I get the following error:

TypeError: saveFile.sync is not a function
     at output (/home/martin/dev/sonos-adapter/node_modules/image-output/index.js:61:19)

The following versions are installed:

It appears that save-file broke backward compat without a major bump.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.