Project

color-rgb

0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
RGB color utilities for converting RGB color into different colorspace (CIE*Lab or XYZ), a different format, or comparing similarity of two colors
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Code Climate

Build Status

Colorkit

A set of utilities to help with dealing with RGB colors. Supporting

  • colorspace conversion from RGB to XYZ or CIE lab*
  • determining distance between two colors using CIE76
  • storing RGB colors as integers

http://en.wikipedia.org/wiki/CIE_1931_color_space http://en.wikipedia.org/wiki/Color_difference#CIE76

Installation

Add this line to your application's Gemfile:

gem 'color-rgb'

And then execute:

$ bundle

Or install it yourself as:

$ gem install color-rgb

then

require 'color-rgb'

Usage

To instantiate an RGB color

Color::RGB.new(r, g, b)          # r, g, b arguments
Color::RGB.from_array([r, g, b]) # an array of RGB values
Color::RGB.from_int(rgb_int)     # int

To convert to XYZ or CIE Lab*

color_rgb = Color::RGB.new(r, g, b)
color_rgb.to_xyz
color_rgb.to_lab

Or to convert to an int for storage

color_rgb = Color::RGB.new(r, g, b)
color_rgb.to_int

Or to go from an Color::RGB instance back to an array of r,g,b values

color_rgb.to_a

To determine distance / similarity between two RGB colors

rgb_one = Color::RGB.new(r, g, b)
rgb_two = Color::RGB.new(other_r, other_g, other_b)

Color::Comparison.distance(rgb_one, rgb_two)

If you are planning to compare rgb_one against a number of colors in sequence tou can instantiate a comparitor object and call compare with any other RGB

rgb_one = Color::RGB.new(r, g, b)

comparitor = Color::Comparison.new(rgb_one)
comparitor.compare(some_other_rgb_color) # Color::RGB isntance
comparitor.compare([r, g, b]) # array of RGB values

Contributing

  1. Fork it ( https://github.com/apartmenttherapy/color-rgb/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request