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
456 downloads per month
Used in 2 crates
200KB
5K
SLoC
auto-palette
🎨 A Rust library for automatically extracting prominent color palettes from images.
Features
[!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++
, andKMeans++
. - Supports multiple color spaces, including
RGB
,HSL
, andLAB
. - Supports the selection of prominent colors based on multiple themes, including
Vivid
,Muted
,Light
, andDark
.
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:
- Fork and clone the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and write tests.
- Test your changes with
cargo test --lib
. - Format the code with
cargo +nightly fmt
andtaplo fmt
. - Create a pull request.
License
This project is distributed under the MIT License. See the LICENSE file for details.
Dependencies
~12MB
~81K SLoC