Black and White dithering for the canvas element
npm install canvas-ditherBlack and White dithering for the canvas element
First, install the package using npm:
npm install canvas-dither --save
Then, require the package and use it like so:
let Dither = require('canvas-dither');
// Assume we have an existing canvas element with a 2D context
// Retrieve the image data of the canvas
let image = context.getImageData(0, 0, canvas.width, canvas.height);
// Dither the data using the Atkinson algoritm
image = Dither.atkinson(image);
// Place the image data back on the canvas
context.putImageData(image, 0, 0);
This package contains the following algorithms:
Dither.threshold(imageData, threshold);
Dither.floydsteinberg(imageData);
Dither.atkinson(imageData);
MIT