#color #image #reduce #set #reduction #rgb

yanked color-reduction

A library to reduce the colors of an image to a specified set of colors

3 releases

0.1.2 Mar 14, 2022
0.1.1 Jul 12, 2021
0.1.0 Jul 12, 2021

#16 in #reduction

MIT license

6KB

color-reduction

Crates.io

A Rust library to reduce the colors of an image to a specified set of colors.

How to Use

Old Image

... combined with ...

use color_reduction::reduce_colors;
use color_reduction::image::Rgb;
use color_reduction::image;

fn main() {
    let image = image::open("./old-image.jpg")
        .expect("error loading image");
    let new_image = reduce_colors(image, &[
        Rgb::from([240,207,149]),
        Rgb::from([24,30,75]),
        Rgb::from([10,6,11]),
        Rgb::from([142,117,98]),
        Rgb::from([67,62,70]),
        Rgb::from([28,42,84]),
        Rgb::from([19,13,20]),
        Rgb::from([248,217,158]),
        Rgb::from([9,4,7]),
        Rgb::from([62,53,52]),
        Rgb::from([62,71,99]),
        Rgb::from([134,125,118]),
        Rgb::from([198,154,106]),
        Rgb::from([15,14,59]),
        Rgb::from([113,90,78]),
        Rgb::from([255, 255, 255]),
        Rgb::from([255, 249, 189]),
    ]);

    new_image.save("./new.jpg").expect("error saving image");
}

... turns into ...

New Image

Dependencies

~13MB
~57K SLoC