ndarray-pixels
WORK IN PROGRESS: Experimental.
Convert ndarray ↔ image data, on Web and Node.js.
Designed to be used with other ndarray-based packages.
In Node.js, this package uses get-pixels and save-pixels. While both packages could be used on the web, they require polyfills for Node.js builtins. Browserify handles that automatically, but more modern bundlers do not. Moreover, the polyfills increase package size significantly. To avoid these problems, web builds of ndarray-pixels
reimplement the same functionality with the more portable Canvas API.
Supported Formats
Quickstart
npm install --save ndarray-pixels
Web
import { getPixels, savePixels } from 'ndarray-pixels';
const bytesIn = await fetch('./input.png')
.then((res) => res.arrayBuffer())
.then((arrayBuffer) => new Uint8Array(arrayBuffer));
const pixels = await getPixels(bytesIn, 'image/png');
const bytesOut = await savePixels(pixels, 'image/png');
Node.js
const fs = require('fs');
const { getPixels, savePixels } = require('ndarray-pixels');
const bufferIn = fs.readFileSync('./input.png');
const pixels = await getPixels(bufferIn, 'image/png');
const bufferOut = await savePixels(pixels, 'image/png');
fs.writeFileSync('./output.png', bufferOut);
To Do