|
1 | 1 | # clancy
|
2 |
| -A library for deriving non-image data from image files |
| 2 | + |
| 3 | +A library for deriving non-image data from image files. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```npm install clancy``` |
| 8 | + |
| 9 | +## Usage |
| 10 | + |
| 11 | +Loading a color palette is an asynchronous operation. You can either await the `loadHistogram` method or use `then` to |
| 12 | +access the palette once it has been loaded. |
| 13 | + |
| 14 | +```javascript |
| 15 | +const { ColorPalette } = require('clancy'); |
| 16 | + |
| 17 | +async function getPalette() { |
| 18 | + const palette = new ColorPalette('path/to/image'); |
| 19 | + await palette.loadHistogram(); |
| 20 | + |
| 21 | + return palette.histogram; |
| 22 | +} |
| 23 | +``` |
| 24 | + |
| 25 | +### Histogram |
| 26 | + |
| 27 | +The histogram algorithm sorts the pixels in an image into sectors in a 3D grid based on their RGB values. The output is |
| 28 | +the average RGB value for each sector in order of sector density. |
| 29 | + |
| 30 | +Some reasonable default parameters are provided for the histogram generation process. The number of sectors can be |
| 31 | +increased using the `dimensionscs` parameter for greater color accuracy and the size of the color palette can be |
| 32 | +adjusted with the `paletteSize` parameter. |
| 33 | + |
| 34 | +## Todo |
| 35 | + |
| 36 | +- [ ] Add more palette generation algorithms (k-means, median cut, etc.) |
| 37 | +- [ ] Add support for transparency/alpha channels |
| 38 | +- [ ] Add image to ASCII conversion |
| 39 | +- [ ] Add browser support |
| 40 | + |
| 41 | +## Notes |
| 42 | + |
| 43 | +- Currently requires Node.js runtime. Browser support is on the todo list. |
| 44 | +- Doesn't yet support transparency and will ignore alpha channels when generating color palette, meaning that the color |
| 45 | + palette will include RGB values for transparent pixels. |
| 46 | +- The palette is stored as an array of objects with `r`, `g`, and `b` properties. This may be subject to change in the |
| 47 | + future. |
0 commit comments