npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

epdoptimize

v0.1.3

Published

Efficiently optimize EPD (Electronic Paper Display) images

Readme

EDP Optimize

Interactive demo 📦📦 📦

A JavaScript library for reducing image colors and dithering them to fit (color) eInk displays with optimal visual quality.

We are using it for our eInk picture frames at paperlesspaper.

The library works with both front end js (using the Browser Canvas API) and node.js (using node-canvas)

Blogpost

Btw. you can order our new Spectra 6 eInk picture frame here. 🎉

Node.js Package

Supported Displays

You can easily add your own displays and use custom color tables.

Intro image

Features

  • Dithering Algorithms: Multiple high-quality dithering options to improve color blending and gradients.
  • Color Calibration: Match device-specific color characteristics for more accurate results.

Installation

npm install epdoptimize

Usage Example

<canvas id="inputCanvas" />
<canvas id="ditheredCanvas" />
<canvas id="ditheredCanvasWithDeviceColors" />
import { ditherImage, getDefaultPalettes, getDeviceColors } from 'epdoptimize';

// Access the canvas elements
const inputCanvas = document.getElementById("inputCanvas");
const ditheredCanvas =  document.getElementById("ditheredCanvas");
const ditheredCanvasWithDeviceColors =  document.getElementById("ditheredCanvasWithDeviceColors");

const palette = getDefaultPalettes('spectra6');
const spectra6colors = getDeviceColors('spectra6'); // Spectra 6 color set (can be default, spectra6 or acep)

const options = {
  algorithm: 'floydSteinberg',
  palette,
};

// Dither the image
const dithered = ditherImage(inputCanvas, ditheredCanvas, options);

// Convert the colors to the displays native colors
const prepared = replaceColors(ditheredCanvas,ditheredCanvasWithDeviceColors {
    originalColors: palette,
    replaceColors: spectra6colors
});

Dithering Options

| Option | Type | Default | Description | | ------------------------ | ---------------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | ditheringType | string | "errorDiffusion" | The main dithering algorithm. Options: errorDiffusion, ordered, random, quantizationOnly. | | errorDiffusionMatrix | string | "floydSteinberg" | Error diffusion kernel. Options: floydSteinberg, falseFloydSteinberg, jarvis, stucki, burkes, sierra3, sierra2, sierra2-4a. | | serpentine | boolean | false | If true, alternates scan direction for each row (serpentine scanning) in error diffusion. | | orderedDitheringType | string | "bayer" | Type of ordered dithering. Currently only bayer is supported. | | orderedDitheringMatrix | [number, number] | [4, 4] | Size of the Bayer matrix for ordered dithering. | | randomDitheringType | string | "blackAndWhite" | Type of random dithering. Options: blackAndWhite, rgb. | | palette | string/array | "default" | Palette to use for quantization. Can be a string (predefined) or a custom array of colors. | | sampleColorsFromImage | boolean | false | If true, generates palette by sampling colors from the image. | | numberOfSampleColors | number | 10 | Number of colors to sample from the image if sampleColorsFromImage is true. |

Add these options to your ditherImage call to customize dithering behavior for your use case.

Convertion Example

How It Works

Color Calibration

eInk displays often render colors less vibrantly than their digital values suggest (e.g., a device red like #ff0000 may appear duller in reality). By calibrating with real-world color measurements, the library ensures that dithering and color reduction use the actual appearance of colors on your target display. After processing, you can map the calibrated colors back to the device's required values.

Dithering Algorithms

Dithering helps create the illusion of intermediate colors by distributing quantization errors across neighboring pixels. This is especially important for eInk displays with limited color palettes.

Available Diffusion Algorithms

| Algorithm | Description | | ----------------------- | -------------------------------------------------------------------------------------------------- | | floydSteinberg | Classic Floyd-Steinberg error diffusion. Distributes error to four neighbors. Visually pleasing. | | falseFloydSteinberg | Simplified Floyd-Steinberg. Distributes error to three neighbors. Faster, slightly different look. | | jarvis | Jarvis, Judice, and Ninke. Spreads error over three rows for smooth gradients, more blurring. | | stucki | Similar to Jarvis, different weights. Balances smoothness and sharpness. | | burkes | Simplified Stucki. Fewer neighbors, less computation, good results. | | sierra3 | Sierra-3 (original). High-quality, less blurring than Jarvis. | | sierra2 | Reduced Sierra-3. Fewer neighbors, faster, less diffusion. | | sierra2-4a | Lightweight, fast. Distributes error to three neighbors. Good for speed-critical use. |

Using Your Own Colors

You can use your own custom color palette by passing an array of colors to the palette option. Colors should be provided as hex strings (e.g., #FF0000).

Example:

const myPalette = [
  "#000000", // black
  "#FFFFFF", // white
  "#FF0000", // red
  "#00FF00", // green
  "#0000FF", // blue
];

const options = {
  ditheringType: "errorDiffusion",
  palette: myPalette,
};

const dithered = ditherImage(image, options);

Resources

Credits


Contributions and feedback are welcome!