#color #colors #colour #css #converter


A library to handle colors easyly. It can parse a string in several formats (hex, rgb, cmyk, hwb, …) into the Color-struct, modifying (grayscale, colorize, …) and output into several string formats.

4 releases

0.1.3 Dec 31, 2018
0.1.2 Nov 25, 2018
0.1.1 Nov 18, 2018
0.1.0 Nov 17, 2018

#55 in Multimedia

Download history 20/week @ 2018-11-21 13/week @ 2018-11-28 34/week @ 2018-12-05 5/week @ 2018-12-12 7/week @ 2018-12-19 15/week @ 2018-12-26 13/week @ 2019-01-02

37 downloads per month

CC0 license

2.5K SLoC


This rust library is intended to do some processing of color values.
It can parse strings in different formats (known color names, hex, rgb, cmyk, hsl, ...) and output color values in different formats. It can also do some basic modifications, like grayscale and colorization.

This library cannot modify images.


For the latest documentation and examples, please go to https://docs.rs/color_processing.


If you have suggestions or found an error, feel free to open an issue or create a pull request on github.


Color crate

This color_processing crate contains functions/methods to handle color values, like converting a rgb color to another colorspace (cmyk, hsl, hwb, ...), parse different kinds of color-strings or modifying colors (inverting, grayscale, colorize, ...).

It's not intended for image manipulation, just for parsing and processing single colors.


use color_processing::Color;

let red = Color::new_rgb(255, 0, 0);
assert_eq!(255, red.red);
assert_eq!(0, red.green);
assert_eq!(0, red.blue);

let grayscaled_red = red.grayscale();
assert_eq!(76, grayscaled_red.red);
assert_eq!(76, grayscaled_red.green);
assert_eq!(76, grayscaled_red.blue);

assert_eq!("#4C4C4C", grayscaled_red.to_hex_string());
assert_eq!("rgb(76, 76, 76)", grayscaled_red.to_rgb_string());
assert_eq!("cmyk(0%, 0%, 0%, 70.2%)", grayscaled_red.to_cmyk_string());
assert_eq!("hsl(0, 0%, 29.8%)", grayscaled_red.to_hsl_string());

// for colorizing:
let colorized_blue = grayscaled_red.colorize_string("blue").unwrap();
assert_eq!("rgb(0, 0, 76)", colorized_blue.to_rgb_string());

// To get the raw values of a specific colorspace:
// The ranges go from 0.0 (0%) to 1.0 (100%).
let raw_rgba = red.get_rgba();
assert_eq!(1.0, raw_rgba.0); // red value
assert_eq!(0.0, raw_rgba.1); // green value
assert_eq!(0.0, raw_rgba.2); // blue value
assert_eq!(1.0, raw_rgba.3); // alpha value

let raw_cmyk = red.get_cmyk();
assert_eq!(0.0, raw_cmyk.0); // cyan value
assert_eq!(1.0, raw_cmyk.1); // magenta value
assert_eq!(1.0, raw_cmyk.2); // yellow value
assert_eq!(0.0, raw_cmyk.3); // key (black) value

// several ways of parsing strings is also possible:
let green = Color::new_string("green").unwrap();
let blue = Color::new_string("rgb(0, 0, 255)").unwrap();
let cyan = Color::new_string("cmyk(100%, 0%, 0%, 0%)").unwrap();
let yellow: Color = "yellow".parse().unwrap();
let magenta = "yellow".parse::<Color>().unwrap();

Now, you should have a notion of what this library can do and if it is the right thing for you!

For all the available functionality, please lookout for the Color-struct.


~36K SLoC