JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 16
  • Score
    100M100P100Q41029F
  • License MIT

dithers images and you can add your own one

Package Exports

  • multidither
  • multidither/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (multidither) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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