Skip to content

marekm4/dominant_color

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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/

About

Simple image color extractor written in Rust with no external dependencies

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages