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
455 downloads per month
150KB
3.5K
SLoC
auto-palette
🎨 A Rust library for automatically extracting prominent color palettes from images.
Features
[!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:
- 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.
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.
Dependencies
~1.1–4MB
~42K SLoC