Home

Awesome

dominant_color

Simple image color extractor written in Rust with no external dependencies

Install

cargo add dominant_color

Usage

use std::path;
use image::EncodableLayout;

fn main() {
    let image = image::open(path::Path::new("docs/Fotolia_45549559_320_480.jpg")).unwrap();

    // if you are sure that you are using RGB image
    let colors = dominant_color::get_colors(image.as_bytes(), false);
    println!("{:?}", colors);

    // if you are not sure
    let colors = dominant_color::get_colors(image.to_rgb8().as_bytes(), false);
    println!("{:?}", colors);

    // if image has alpha channel
    let colors = dominant_color::get_colors(image.to_rgba8().as_bytes(), true);
    println!("{:?}", colors);
}

Example

Image

Colors

Demo

https://dominant-color-demo.marekm4.com/