Crates.io | iris-lib |
lib.rs | iris-lib |
version | 0.1.0 |
source | src |
created_at | 2022-08-13 09:33:58.68145 |
updated_at | 2022-08-13 09:33:58.68145 |
description | A library that creates color palettes from images using the median cut algorithm. |
homepage | https://github.com/Kaesebrot84/iris-lib |
repository | https://github.com/Kaesebrot84/iris-lib |
max_upload_size | |
id | 644694 |
size | 545,552 |
Generate color palettes from pixels or images using the mediancut algorithm.
Include iris-lib
in your Cargo.toml:
iris-lib = "0.1.0"
Create palettes from pixels:
use iris_lib::color_bucket::ColorBucket;
use iris_lib::color::Color;
fn main() {
let colors = vec![
Color { r: 255, g: 0, b: 0, a: 0 },
Color { r: 0, g: 255, b: 0, a: 0 },
Color { r: 0, g: 0, b: 255, a: 0 }
];
if let Some(mut bucket) = ColorBucket::from_pixels(colors) {
let palette = bucket.make_palette(3); // three iterations
println!("{:?}", palette);
};
}
Result:
[Color { r: 255, g: 0, b: 0, a: 0 },
Color { r: 0, g: 255, b: 0, a: 0 },
Color { r: 0, g: 0, b: 255, a: 0 }]
Include the image
feature in your Cargo.toml
reference.
iris-lib = { version = "0.1.0", features = ["image"]}
Create palettes by passing the path of the target image:
use iris_lib::color_bucket::ColorBucket;
fn main() {
if let Some(mut bucket) = ColorBucket::from_image("peppers.png") {
let palette = bucket.make_palette(2); // two iterations
println!("{:?}", palette);
};
}
Result:
[Color { r: 165, g: 197, b: 124, a: 255 },
Color { r: 144, g: 172, b: 74, a: 255 },
Color { r: 192, g: 51, b: 42, a: 255 },
Color { r: 97, g: 42, b: 25, a: 255 }]
Check out iris the command line tool built on top of this library.