🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

color-diff

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
c

color-diff

Implemets the CIEDE2000 color difference algorithm, conversion between RGB and LAB color and mapping all colors in palette X to the closest or most different color in palette Y based on the CIEDE2000 difference.

1.4.0
latest
100

Supply Chain Security

100

Vulnerability

99

Quality

100

Maintenance

100

License

Version published
Weekly downloads
314K
0.26%
Maintainers
1
Weekly downloads
 
Created
Issues
3

What is color-diff?

The color-diff npm package is used for color difference calculations and color palette reduction. It provides utilities to find the closest color match from a palette and to calculate the difference between colors using various algorithms.

What are color-diff's main functionalities?

Calculate Color Difference

This feature allows you to calculate the difference between two colors. The `diff` function takes two color objects and returns a numerical value representing the difference.

const colorDiff = require('color-diff');

const color1 = { R: 255, G: 0, B: 0 };
const color2 = { R: 0, G: 255, B: 0 };
const difference = colorDiff.diff(color1, color2);
console.log(difference);

Find Closest Color

This feature allows you to find the closest color from a given palette. The `closest` function takes a color object and a palette array, and returns the closest matching color from the palette.

const colorDiff = require('color-diff');

const palette = [
  { R: 255, G: 0, B: 0 },
  { R: 0, G: 255, B: 0 },
  { R: 0, G: 0, B: 255 }
];
const color = { R: 128, G: 128, B: 0 };
const closestColor = colorDiff.closest(color, palette);
console.log(closestColor);

Palette Reduction

This feature allows you to reduce a set of colors to a given palette. The `map_palette` function takes an array of colors and a palette, and returns a new array where each color is replaced by the closest color from the palette.

const colorDiff = require('color-diff');

const colors = [
  { R: 255, G: 0, B: 0 },
  { R: 0, G: 255, B: 0 },
  { R: 0, G: 0, B: 255 },
  { R: 128, G: 128, B: 0 }
];
const palette = [
  { R: 255, G: 0, B: 0 },
  { R: 0, G: 255, B: 0 }
];
const reducedColors = colorDiff.map_palette(colors, palette);
console.log(reducedColors);

Other packages similar to color-diff

FAQs

Package last updated on 31 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts