GithubHelp home page GithubHelp logo

color-namer's Introduction

Color Namer Build Status

Give me a color and I'll name it.

Color Namer is an npm package for use in Node.js or the browser that calculates color distance using the Delta-E color difference technique. Given a color in Hexadecimal RGB, RGBA, HSL, or HSV format, it converts the color to the Lab* color space, then calculates the color's Euclidean distance from a set of colors with known names.

Mike Bostock of D3 fame explains it well:

Lab and HCL color spaces are special in that the perceived difference between two colors is proportional to their Euclidean distance in color space. This special property, called perceptual uniformity, makes them ideal for accurate visual encoding of data. In contrast, the more familiar RGB and HSL color spaces distort data when used for visualization.

Lists

The color names are derived from several lists:

Installation

npm install color-namer --save

Usage

Require the module:

var namer = require('color-namer')
var names = namer("#FF0000")

From the above code, names will have a key for each list:

names.roygbiv
names.basic
names.html
names.x11
names.pantone
names.ntc

Each list is an array of colors, sorted by their perceptual similarity to the given color:

[
  { name: 'red',
    hex: '#FF0000',
    distance: 0
  },{
    name: 'orangered',
    hex: '#FF4500',
    distance: 13.170205025755513
  },{
    name: 'tomato',
    hex: '#FF6347',
    distance: 31.733444038510665
  },{
    name: 'crimson',
    hex: '#DC143C',
    distance: 35.38084849496472
  },{
    name: 'firebrick',
    hex: '#B22222',
    distance: 40.71076805218006
  },{
    name: 'coral',
    hex: '#FF7F50',
    distance: 42.340752375722616
  },{
    name: 'chocolate',
    hex: '#D2691E',
    distance: 44.378454180212145
  }
]

Other input format work too like HSL, RGB, and RGBA:

name("hsl(50,100%,50%)")
name("rgb(255,0,0)")
name("rgba(255,0,0,1)")

Options

options.pick

This option allows us to derive names from the dedicated lists for faster computation.

var names = namer(color, { pick: ['basic', 'x11'] })
// output: { basic: [...], x11: [...] }

options.omit

The opposite of options.pick.

var names = namer(color, { omit: ['pantone', 'roygbiv'] })
// output: { basic: [...], html: [...], x11: [...], ntc: [...] }

options.distance

If 'deltaE', use the Delta-E distance function, otherwise uses default distance function.

var names = namer(color, { pick: ['basic'], distance: 'deltaE' });
// output: { basic: [...] }

Tests

npm install
npm test

License

MIT

color-namer's People

Contributors

zeke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

color-namer's Issues

Update npm package

Hi,

Could you publish the latest version to npm please? The current npm version is missing some of the colour mappings and has a different API.

Thanks for the useful module.

Two Questions: Not working in Svelte, and File size

So when I try importing in Svelte, I get the following error in console:

npm run dev

> color-convert@1.0.0 dev
> svelte-kit dev

Pre-bundling dependencies:
  svelte/store
  svelte
  color-namer
  dino-color-picker
  lodash.merge
  (...and 5 more)
(this will be run only when your dependencies or config have changed)
 > node_modules/d/index.js:7:30: error: Could not read from file: C:\Users\justi\Documents\GitHub\colorpicker\node_modules\es5-ext\string\index.js#\contains
    7 │   , contains        = require("es5-ext/string/#/contains");
      ╵                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~

 > node_modules/es6-iterator/index.js:3:23: error: Could not read from file: C:\Users\justi\Documents\GitHub\colorpicker\node_modules\es5-ext\array\index.js#\clear    
    3 │ var clear    = require("es5-ext/array/#/clear")
      ╵                        ~~~~~~~~~~~~~~~~~~~~~~~

> Build failed with 2 errors:
node_modules/d/index.js:7:30: error: Could not read from file: C:\Users\justi\Documents\GitHub\colorpicker\node_modules\es5-ext\string\index.js#\contains
node_modules/es6-iterator/index.js:3:23: error: Could not read from file: C:\Users\justi\Documents\GitHub\colorpicker\node_modules\es5-ext\array\index.js#\clear       
Error: Build failed with 2 errors:
node_modules/d/index.js:7:30: error: Could not read from file: C:\Users\justi\Documents\GitHub\colorpicker\node_modules\es5-ext\string\index.js#\contains
node_modules/es6-iterator/index.js:3:23: error: Could not read from file: C:\Users\justi\Documents\GitHub\colorpicker\node_modules\es5-ext\array\index.js#\clear       
    at failureErrorWithLog (C:\Users\justi\Documents\GitHub\colorpicker\node_modules\esbuild\lib\main.js:1493:15)
    at C:\Users\justi\Documents\GitHub\colorpicker\node_modules\esbuild\lib\main.js:1151:28
    at runOnEndCallbacks (C:\Users\justi\Documents\GitHub\colorpicker\node_modules\esbuild\lib\main.js:941:63)
    at buildResponseToResult (C:\Users\justi\Documents\GitHub\colorpicker\node_modules\esbuild\lib\main.js:1149:7)
    at C:\Users\justi\Documents\GitHub\colorpicker\node_modules\esbuild\lib\main.js:1258:14
    at C:\Users\justi\Documents\GitHub\colorpicker\node_modules\esbuild\lib\main.js:629:9
    at handleIncomingPacket (C:\Users\justi\Documents\GitHub\colorpicker\node_modules\esbuild\lib\main.js:726:9)
    at Socket.readFromStdout (C:\Users\justi\Documents\GitHub\colorpicker\node_modules\esbuild\lib\main.js:596:7)
    at Socket.emit (node:events:390:28)
    at Socket.emit (node:domain:475:12)

And on page:

SyntaxError 500
The requested module '/node_modules/lodash.merge/index.js' does not provide an export named 'default'

I've been dealing with this error seemingly forever, but the project worked fine until I added this package, and removing it makes it work fine again.

import namer from 'color-namer'; results in this error and so does the async way:

onMount(async () => {
		const namer = await import('color-namer');

My second question is why the file size is so massive. 118.2kb for something with a file size that should be almost entirely composed of the lists of colors it uses is a bit much to me. Compressed, the colors should probably only be 40kb or so as a rough guess. I was just wondering why the code is 9000+ lines and why there are so many dependencies.

This package looks awesome, nice work and can't wait to use it. Thanks in advance.

how do I get NTC colors?

colorNamer(myHex) only ever seems to return a small, predefined set of colors. Is this intentional?

Inclusion of standardized palettes

Lightness in Lab

IMHO for determine color in L_a_b color space - Lightness is least important
So I think is needed reduce the L in Lab, for reduce its impact

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.