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

auto-palette

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

3 unstable releases

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

#139 in Images

Download history 309/week @ 2024-04-29 146/week @ 2024-05-06

455 downloads per month

MIT license

150KB
3.5K SLoC

auto-palette

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

CI License Version Codacy Badge Codecov FOSSA Status

Features

Hot air balloon on blue sky Extracted Color Palette

[!NOTE] Photo by Laura Clugston on Unsplash

  • Extract prominent color palettes from images automatically.
  • Provide detailed color information color, position, and population.
  • Support multiple color palette extraction algorithms. (DBSCAN, DBSCAN++, KMeans++)

Installation

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

[dependencies]
auto-palette = "0.2.0"

Usage

Here is a basic example that demonstrates how to extract the color palette and find the dominant 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("tests/assets/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 dominant 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.

For more information, see Contributing guide.

Contributing

Contributions are welcome! For detailed information on how to contribute, please refer to Contributing guide.
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

Dependencies

~1.1–4MB
~42K SLoC