Skip to content

dominicbrindley/floyd-steinberg-dithering

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

floyd-steinberg-dithering

A command line interface (CLI) tool for executing a grayscale Floyd-Steinberg dithering algorithm in Node.js.

Input Output

What does it do?

Dithering is the process of adding noise to an image. It can create the appearance of shading when the color range is limited by strategically spacing pixels, and is useful to reduce file size when image fidelity is not paramount. The Floyd-Steinberg algorithm diffuses each pixel’s error to neighboring pixels, which can create a visual “blending” effect.

Installation

git clone [email protected]:emilymdubois/floyd-steinberg-dithering.git
cd floyd-steinberg-dithering
npm link

Usage

This script expects a valid filepath to a JPEG or PNG image. The output of the dithering algorithm is written to a file of the same type, suffixed with _dithered, in the same directory as the input file.

$ floyd-steinberg-dithering path/to/file.png
# Output will be written to path/to/file_dithered.png

If you’d prefer to call the Node.js functions directly from a Node.js file, you can use a symbolic link to import the functions as dependencies:

cd another/project
npm link floyd-steinberg-dithering
#!/usr/bin/env node

import dither, {write} from 'floyd-steinberg-dithering';

const inputPath = 'path/to/file.png';

dither(inputPath).then((image) => {
  const outputPath = write(inputPath, image);
  console.log('Wrote dithered output to', outputPath);
});

Testing

$ npm test

About

A Floyd-Steinberg image dithering algorithm

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%