# colors-clustering

> Colors clustering based on K-means algorithm & CIE76. The seeds are extended color keywords from CSS Color Module Level 3 (W3C Recommendation 07 June 2011).

Latest version **0.1.1** (published 2014-05-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install colors-clustering
pnpm add colors-clustering
yarn add colors-clustering
bun add colors-clustering
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2014-05-08 |
| First published | 2014-05-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Zeno Zeng |
| Maintainers | zenozeng |
| Keywords | color, k-means, clustering, lab, CIE67 |

## Links

- npm: https://www.npmjs.com/package/colors-clustering
- Homepage: https://github.com/zenozeng/colors-clustering
- Issues: https://github.com/zenozeng/colors-clustering/issues
- npm.io page: https://npm.io/package/colors-clustering

## Dependencies (2)

- [color-convert](https://npm.io/package/color-convert.md) latest
- [canvas-browserify](https://npm.io/package/canvas-browserify.md) >=1.1.1

## Alternatives

- [postcss-color-hex-alpha](https://npm.io/package/postcss-color-hex-alpha.md) — 6.4M weekly downloads
- [randomcolor](https://npm.io/package/randomcolor.md) — 348.0K weekly downloads
- [bows](https://npm.io/package/bows.md) — 1.3K weekly downloads
- [ep_prefer_color_scheme](https://npm.io/package/ep_prefer_color_scheme.md) — 260 weekly downloads
- [coc-yank](https://npm.io/package/coc-yank.md) — 61 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2014-05-08
- 0.1.0 — 2014-05-08

## README

# Colors Clustering

Colors clustering based on K-means algorithm & CIE76.  
The seeds are extended color keywords from 
CSS Color Module Level 3 (W3C Recommendation 07 June 2011).

## Usage

### Get img src

You can use

- Url

- Data Url

- URL.createObjectURL(FileObj)

### Browser

Include browser/colors-clustering.js.

```javascript
window.colorsClustering({src: imgSrc}, function(colors) {
    // do sth here
});
```

see also: example/index.html

### NodeJS or Browserify

```
npm install colors-clustering
```

```javascript
var colorsClustering = require("colors-clustering");
colorsClustering({src: imgSrc}, function(colors) {
    // do sth here
});
```

### Config

```javascript
var config = {
    debug: true,
    log: function(msg, colors) {
        console.log(msg);
        colors.map(function(rgb) {
            console.log(rgb);
        });
    },
    maxWidth: 30,
    maxHeight: 30,
    minCount: 1,
    src: imgSrc
};
colorsClustering(config, callback);
```

The image will be resized based on maxWidth and maxHeight.
And the number of output colors will be always >= minCount.
If debug is on, the log will be called.

### Example Output

Note: Color is [r, g, b], and the weight depends on the size of cluster.

```json
[
  {
    "color": [
      38,
      36,
      26
    ],
    "weight": 0.14166666666666666
  },
  {
    "color": [
      211,
      192,
      131
    ],
    "weight": 0.008333333333333333
  },
  {
    "color": [
      221,
      204,
      142
    ],
    "weight": 0.01875
  },
  {
    "color": [
      105,
      99,
      76
    ],
    "weight": 0.004166666666666667
  },
  {
    "color": [
      77,
      73,
      56
    ],
    "weight": 0.010416666666666666
  },
  {
    "color": [
      233,
      218,
      163
    ],
    "weight": 0.7708333333333334
  },
  {
    "color": [
      216,
      204,
      159
    ],
    "weight": 0.0020833333333333333
  },
  {
    "color": [
      232,
      218,
      161
    ],
    "weight": 0.035416666666666666
  },
  {
    "color": [
      159,
      147,
      105
    ],
    "weight": 0.004166666666666667
  },
  {
    "color": [
      197,
      184,
      144
    ],
    "weight": 0.004166666666666667
  }
] 
```

## License (MIT)

Copyright (c) 2014 Zeno Zeng

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*This program incorporates work covered by the following copyright and permission notices:*

- canvas-browserify

    Copyright (c) 2013 Dominic Tarr

    MIT License
    
- color-convert

    Copyright (c) 2011-2014 harthur

    MIT License

## FAQ

### Why not CIEDE2000

For performance issues.
Using CIEDE2000 is unbearable time-consuming.

### Is canvas(node) an optionalDependencie?

Yes, it is. If you only want to use this package in browser, 
it doesn't matter if you fail to npm install canvas.

---
_Source: https://npm.io/package/colors-clustering · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
