🎨 Pigmnts

Pigmnts is a library to create a color palette from an image built using Rust, compiled to WebAssembly. This allows for super-fast color palette extraction from an image on the web. It uses the K-means++ clustering algorithm to select the most commonly occuring colors from the image.

Examples with Web Assembly

As a JavaScript module

```html

```

In Node.js

  1. Start by installing the npm package bash npm install pigmnts

  2. Configure your build process to copy the wasm file in the your build directory.

  3. Use it in code

```javascript import init, { pigments } from 'pigmnts';

async function run() { // Load the wasm file from path where wasm file was copied by the bundler await init('');

// Canvas element from which palette should be created const canvas = document.querySelector('canvas');

// Call the pigments wasm function const palette = pigments(canvas, 5); } run(); ```

Functions

Pigmnts exposes following function in WebAssembly

pigments(canvas: HtmlCanvasElement, k: number, mood: Mood|number, batch_size: number)

Arguments
Return

Returns an Array of Objects where each Object is a color of the following format. javascript [ { dominance: 0.565 // Dominance of color in image(From 0 to 1) hex: '#6DDAD0' // 6-digit Hex color code rgb: { // Equivalent RGB color r: 109, g: 218, b: 208 }, hsl: { // Equivalent HSL color (Normalized to 0-1) h: 0.48333, s: 0.6, l: 0.64, } }, // Other colors { ... } ]

If this crate is used in some Rust projects, then following function is also available

pigmentspixels(pixels: &Vec<LAB>, k: u8, weight: fn(&LAB) -> f32, maxiter: Option<u16>) -> Vec<(LAB, f32)>

This function can be used when color data is gathered from an image decoded using image-rs.

Arguments
Return

Returns a vector of tuples with colors as LAB and dominance(as percentage) of each color found in the image.

License

Pigmnts is MIT Licensed