#color-palette #palette #image #color-space #color #graphics #color-extraction

auto-palette

🎨 A Rust library that extracts prominent color palettes from images automatically

4 releases (2 breaking)

new 0.3.0 May 19, 2024
0.2.0 May 9, 2024
0.1.1 Apr 30, 2024
0.1.0 Apr 29, 2024

#107 in Images

Download history 90/week @ 2024-04-23 219/week @ 2024-04-30 147/week @ 2024-05-07

456 downloads per month
Used in 2 crates

MIT license

200KB
5K SLoC

auto-palette

🎨 A Rust library for automatically extracting prominent color palettes from images.

Build License Version Codacy grade Codecov

Features

Hot air balloon on blue sky Extracted Color Palette

[!NOTE] Photo by Laura Clugston on Unsplash

  • Automatically extracts prominent color palettes from images.
  • Provides detailed information on color, position, and population.
  • Supports multiple extraction algorithms, including DBSCAN, DBSCAN++, and KMeans++.
  • Supports multiple color spaces, including RGB, HSL, and LAB.
  • Supports the selection of prominent colors based on multiple themes, including Vivid, Muted, Light, and Dark.

Installation

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

[dependencies]
auto-palette = "0.3.0"

Usage

Here is a basic example that demonstrates how to extract the color palette and find the prominent colors. 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("../../gfx/holly-booth-hLZWGXy5akM-unsplash.jpg").unwrap();

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

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

Development

Follow the instructions below to build and test the project:

  1. Fork and clone the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes and write tests.
  4. Test your changes with cargo test --lib.
  5. Format the code with cargo +nightly fmt and taplo fmt.
  6. Create a pull request.

License

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

FOSSA Status

Dependencies

~12MB
~81K SLoC