
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
image-output
Advanced tools
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(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:
{data: Uint8Array, width, height}
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 . |
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. |
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
© 2018 Dmitry Yv. MIT License.
FAQs
Output image data to a file, console, canvas, array or buffer
The npm package image-output receives a total of 1,721 weekly downloads. As such, image-output popularity was classified as popular.
We found that image-output demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.