Convert::Color - color space conversions and named lookups
Convert::Color
use Convert::Color; my $color = Convert::Color->new( 'hsv:76,0.43,0.89' ); my ( $red, $green, $blue ) = $color->rgb; # GTK uses 16-bit values my $gtk_col = Gtk2::Gdk::Color->new( $color->rgb16 ); # HTML uses #rrggbb in hex my $html = '<td bgcolor="#' . $color->rgb8_hex . '">';
This module provides conversions between commonly used ways to express colors. It provides conversions between color spaces such as RGB and HSV, and it provides ways to look up colors by a name.
This class provides a base for subclasses which represent particular color values in particular spaces. The base class provides methods to represent the color in a few convenient forms, though subclasses may provide more specific details for the space in question.
For more detail, read the documentation on these classes; namely:
Convert::Color::RGB - red/green/blue as floats between 0 and 1
Convert::Color::RGB8 - red/green/blue as 8-bit integers
Convert::Color::RGB16 - red/green/blue as 16-bit integers
Convert::Color::HSV - hue/saturation/value
Convert::Color::HSL - hue/saturation/lightness
The following classes are subclasses of one of the above, which provide a way to access predefined colors by names:
Convert::Color::VGA - named lookup for the basic VGA colors
Convert::Color::X11 - named lookup of colors from X11's rgb.txt
Return a new value to represent the color specified by the string. This string should be prefixed by the name of the color space to which it applies. For example
rgb:RED,GREEN,BLUE rgb8:RRGGBB rgb16:RRRRGGGGBBBB hsv:HUE,SAT,VAL hsl:HUE,SAT,LUM vga:NAME vga:INDEX x11:NAME
For more detail, see the constructor of the color space subclass in question.
Returns the individual red, green and blue color components of the color value. For RGB values, this is done directly. For values in other spaces, this is done by first converting them to an RGB value using their to_rgb() method.
to_rgb()
Returns the individual red, green and blue color components of the color value in RGB8 space. For RGB8 values, this is done directly. For values in other spaces, this is done by first converting them to an RGB value using their to_rgb() method, then converting that to RGB8.
Returns the individual red, green and blue color components of the color value in RGB16 space. For RGB16 values, this is done directly. For values in other spaces, this is done by first converting them to an RGB value using their to_rgb() method, then converting that to RGB16.
Returns a string representation of the color components in the RGB8 space, in a convenient RRGGBB hex string, likely to be useful HTML, or other similar places.
RRGGBB
Returns a string representation of the color components in the RGB16 space, in a convenient RRRRGGGGBBBB hex string.
RRRRGGGGBBBB
Most subclasses should support the following methods and behaviours. Note that this list is just a guide; the documentation for the specific class in question. As well as the following, it is likely the subclass will provide accessors to directly obtain the components of its representation in the specific space.
Return a new value representing the color in RGB space
Return a new value representing the color in RGB8 space
Return a new value representing the color in RGB16 space
Return a new value representing the color in HSV space
Return a new value representing the color in HSL space
Paul Evans <leonerd@leonerd.org.uk>
To install Convert::Color, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Convert::Color
CPAN shell
perl -MCPAN -e shell install Convert::Color
For more information on module installation, please visit the detailed CPAN module installation guide.