Skip to content

🎨 Automatically extract prominent color palettes from images, available as a Rust library, WebAssembly module, and CLI tool.

License

Notifications You must be signed in to change notification settings

t28hub/auto-palette

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

auto-palette

🎨 auto-palette is a library that automatically extracts prominent color palettes from images, available as Rust library, WebAssembly and CLI tool.

Build License Version Codacy grade Codecov

Overview

auto-palette is a Rust project that offers color palette extraction from images. It consists of the following components:

  • auto-palette: Core library for programmatic usage.
  • auto-palette-cli: Command-line interface for easy usage.
  • auto-palette-wasm: WebAssembly version for browser usage.

Perfect for developers, designers and anyone needing efficient color palette extraction.

Features

Hot air balloon on blue sky

Theme Color Palette
(Default) Default
Colorful Colorful
Vivid Vivid
Muted Muted
Light Light
Dark Dark

Note

Photo by Laura Clugston on Unsplash

  • Automatically extracts prominent color palettes from images.
  • Provides detailed color swatch information (color, position, population)
  • Supports multiple extraction algorithms: DBSCAN, DBSCAN++, and KMeans++.
  • Supports numerous color spaces: RGB, HSL, LAB, LCHuv, ANSI256 and more.
  • Theme-based swatch selection: Colorful, Vivid, Muted, Light, and Dark.
  • Available as a Rust library, Wasm, and a CLI tool.

Installation

Rust Library

To use auto-palette in your Rust project, add it to your Cargo.toml.

[dependencies]
auto-palette = "0.7.0"

CLI Tool

To use command-line interface, install the auto-palette-cli crate.

cargo install auto-palette-cli

Usage

Rust Example

Here is an example of extracting the color palette from an image using the Rust library. See the examples directory for more examples.

use auto_palette::{ImageData, Palette};

fn main() {
  // Load the image data from the file
  let image_data = ImageData::load("tests/assets/holly-booth-hLZWGXy5akM-unsplash.jpg").unwrap();

  // Extract the color palette from the image data
  let palette: Palette<f64> = Palette::extract(&image_data).unwrap();
  println!("Extracted {} swatches", palette.len());

  // Find the 5 dominant colors in the palette and print their information
  let swatches = palette.find_swatches(5).unwrap();
  for swatch in swatches {
    println!("Color: {}", swatch.color().to_hex_string());
    println!("Position: {:?}", swatch.position());
    println!("Population: {}", swatch.population());
    println!("Ratio: {}", swatch.ratio());
  }
}

CLI Example

Here is an example of extracting the color palette from an image using the CLI tool.

$ auto-palette path/to/your_image.jpg -n 6 -c rgb -o table
+---+--------------------+------------+------------+
| # | Color              | Position   | Population |
+---+--------------------+------------+------------+
| 1 | RGB(221, 226, 222) | (104, 96)  |       6778 |
| 2 | RGB(3, 144, 149)   | (114, 201) |       5476 |
| 3 | RGB(23, 37, 36)    | (120, 300) |       4300 |
| 4 | RGB(36, 88, 131)   | (183, 145) |       1348 |
| 5 | RGB(254, 29, 44)   | (183, 190) |        779 |
| 6 | RGB(253, 213, 116) | (25, 158)  |        567 |
+---+--------------------+------------+------------+

Development

See the CONTRIBUTING guidelines.

Contributing

Contributions are welcome! For detailed information on how to contribute, please refer to CONTRIBUTING guidelines.
Please note that this project is released with a CODE_OF_CONDUCT. By participating in this project you agree to abide by its terms.

License

This project is distributed under the MIT License. See the LICENSE file for details.

FOSSA Status

About

🎨 Automatically extract prominent color palettes from images, available as a Rust library, WebAssembly module, and CLI tool.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •