multidither

1.0.5 • Public • Published

This is a simple dither that you can extend with your own algorithms.

Installation

npm i multidither

Example

const { ColorPalette, FloydSteinbergDither } = require("multidither");
const Jimp = require("jimp");

Jimp.read("./file.png", (err, img) => {
  if (err) throw err;

  let dither = new FloydSteinbergDither(
    img,
    new ColorPalette([
      "#000000",
      "#ffffff",
      "#ff0000",
      "#00ff00",
      "#0000ff",
      "#ffff00",
      "#ff00ff",
      "#00ffff",
    ])
  );

  dither.dither("./out.png");
});

Docs

new FloydSteinbergDither(Jimp image, ColorPalette palette)


Dither.dither(string outputPath, bool shouldSave)

new ColorPalette(string[]| {r:number, g:number,b:number,a:number}[] colors) // hex array or grb / grba array

//Palette.nc = https://www.npmjs.com/package/nearest-rgba

making own dither algorithms

const { BaseDither } = require("multidither");
class MyDither extends BaseDither {
  constructor(image, palette) {
    super(image, palette);
  }

  dither(path, write = true) {
    // gets called when a dither process is started. this also calls onPixel
  }
  onPixel(x, y) {
    // gets called for every pixel at position x, y
  }
}

Additional info

  • I made that package intirely by myself exept the jimp package

Package Sidebar

Install

npm i multidither

Weekly Downloads

1

Version

1.0.5

License

MIT

Unpacked Size

6.56 kB

Total Files

6

Last publish

Collaborators

  • 1euro7cent