Pixels is a tiny image processing library written in JavaScript.
$ npm install pixels
$ npm test
var px = require('pixels');
Currently supports read/write for PNG and JPEG.
Read image into a Float64Array
.
var image = px.read('./test/input.jpg', Float64Array);
Reduce image into grayscale bitmap.
// reduce [r, g, b, a, ...] => [x, ...]
px.reduce(image,
(r, g, b, a) =>
0.2126 * r +
0.7152 * g +
0.0722 * b
);
Expand back to original size and set alpha
to a random value.
// expand [x, ...] => [r, g, b, a, ...]
px.expand(image,
(x) =>
[x, x, x, Math.random()]
);
Output to file.
px.write('./test/output.png', image);
px.write('./test/output.jpg', image);
Original | Processed PNG | Processed JPEG |
---|---|---|
All this in 5 lines of code. You can also access the image data directly through image.data
.
See test/test.js
.
Reads an image file
into the specified type
(TypedArray
).
Writes an image
to file
.
Reduces blocks of data in an image
. Block size is inferred from the number of arguments in f
. See blockman.
Expands blocks of data in an image
. Block size is inferred from the number of arguments in f
. See blockman.
Iterates and applies a mapping function over blocks of data in an image
. See blockman.