12 releases

new 0.3.3 May 25, 2024
0.3.2 May 8, 2024
0.2.1 Mar 14, 2024
0.1.6 Feb 2, 2024
0.1.1 Dec 31, 2023

#97 in Images

Download history 14/week @ 2024-02-03 28/week @ 2024-02-10 182/week @ 2024-02-17 284/week @ 2024-02-24 253/week @ 2024-03-02 353/week @ 2024-03-09 289/week @ 2024-03-16 289/week @ 2024-03-23 201/week @ 2024-03-30 180/week @ 2024-04-06 142/week @ 2024-04-13 136/week @ 2024-04-20 310/week @ 2024-04-27 566/week @ 2024-05-04 184/week @ 2024-05-11 249/week @ 2024-05-18

1,328 downloads per month
Used in 2 crates

Apache-2.0

340KB
7.5K SLoC

Material colors

An unofficial port of the material-color-utilities library for creating Material You themes and color schemes.

Examples

From HEX color:

use std::str::FromStr;
use material_colors::{color::Argb, theme::ThemeBuilder};

fn main() {
    let theme = ThemeBuilder::with_source(Argb::from_str("aae5a4").unwrap()).build();

    // Do whatever you want...
}

From image:

⚠️ Before obtaining an array of ARGB pixels for the image, it is recommended (but not necessary if your image is already small in size or you just don't mind about execution time) to adjust its dimensions to 128x128 by func:resize from struct:Image provided by struct:ImageReader. The reason is described here.

use material_colors::{
    image::{FilterType, ImageReader},
    theme::ThemeBuilder,
};

#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
    let image = reqwest::get("https://picsum.photos/id/866/1920/1080")
        .await?
        .bytes()
        .await?
        .to_vec();

    let mut data = ImageReader::read(image).expect("failed to read image");

    // Lancsoz3 takes a little longer, but provides the best pixels for color extraction.
    // However, if you don't like the results, you can always try other FilterType values.
    data.resize(128, 128, FilterType::Lanczos3);

    let theme = ThemeBuilder::with_source(ImageReader::extract_color(&data)).build();

    // Do whatever you want...

    Ok(())
}

Dependencies

~1.5–4.5MB
~39K SLoC