Skip to content

colorjs/color-namer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Color Namer

Give me a color and I'll name it.

Color Namer is a node module that calculates color distance using the Delta-E color difference technique. Given a color in some format like RGB, HSL, or HSV, it uses the awesome chroma-js node module to convert the color to the Lab* color space, then calculates the color's Euclidean distance from a set of colors with known names.

Installation

npm install color-namer --save

Usage

Easy peasy:

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

The function returns an array of colors objects, sorted by proximity in the Lab* color space:

[
  { 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
  }
]

Sets

By default, names are chosen from a small set of basic colors.

// These are equivalent:
namer("#FF0000")
namer("#FF0000", 'basic')

To use the HTML color names:

namer("#FF0000", 'html')

Or good ol' ROYGBIV:

namer("#FF0000", 'roygbiv')

Or bring your own name data:

namer("#FF0000", [
  { name: 'black', hex: '#000' },
  { name: 'white', hex: '#FFF' }
])

Tests

npm install
npm test

License

WTFPL