1NAME
2 Color::Rgb - Simple rgb.txt parsing class
3
4SYNOPSIS
5 use Color::Rgb;
6 $rgb = new Color::Rgb(rgb_txt=>'/usr/X11R6/lib/X11/rgb.txt');
7
8 @rgb = $rgb->rgb('red'); # returns 255, 0, 0
9 $red = $rgb->rgb('red', ','); # returns the above rgb list as
10 # comma separated string
11 $red_hex=$rgb->hex('red'); # returns 'FF0000'
12 $red_hex=$rgb->hex('red', '#'); # returns '#FF0000'
13
14 $my_hex = $rgb->rgb2hex(255,0,0); # returns 'FF0000'
15 $my_rgb = $rgb->hex2rgb('#FF0000'); # returns list of 255,0,0
16
17DESCRIPTION
18 Color::Rgb - simple rgb.txt parsing class. It will also help you to
19 convert rgb color values to hex and vice-versa.
20
21METHODS
22 * "new([rgb_txt="$rgb_file])> - constructor method. Returns a
23 Color::Rgb object. Optionally accepts a path to the rgb.txt file. If
24 you ommit the file, it will use the path in the $Color::Rgb::RGB_TXT
25 variable, which defaults to "'/usr/X11R6/lib/X11/rgb.txt'". It
26 means, instead of using rgb_txt=>'' option, you could also set the
27 value of the $Color::Rgb::RGB_TXT variable to the correct path
28 before you call the the new() entry elsewhere in this document
29 constructor (but definitely after you load the Color::Rgb class with
30 "use" or "require").
31
32 Note: If your system does not provide with any rgb.txt file,
33 Color::Rgb distribution includes an rgb.txt file that you can use
34 instead.
35
36 * "rgb($alias [,$delimiter])" - returns list of numeric Red, Green and
37 Blue values for an $alias delimited (optionally) by a $delimiter .
38 Alias is name of the color in the English language (Ex., 'black',
39 'red', 'purple' etc.).
40
41 Examples:
42
43 my ($r, $g, $b) = $rgb->rgb('blue'); # returns list: 00, 00, 255
44 my $string = $rgb->rgb('blue', ','); # returns string: '00,00,255'
45
46 If alias does not exist in the rgb.txt file it will return undef.
47
48 * "hex($alias [,$prefix])" - similar to the rgb($alias) manpage
49 method, but returns hexedecimal string representing red, green and
50 blue colors, prefixed (optionally) with $prefix. If $alias does not
51 exist in the rgb.txt file it will return undef
52
53 * "rgb2hex($r, $g, $b [,$prefix])" - converts rgb value to hexidecimal
54 string. This method has nothing to do with the rgb.txt file, so none
55 of the arguments need to exist in the rgb.txt.
56
57 Examples,
58
59 @rgb = (128, 128, 128); # RGB represantation of grey
60 $hex_grey = $rgb->rgb2hex(@rgb); # returns string 'C0C0C0'
61 $hex_grey = $rgb->rgb2hex(@rgb, '#'); # returns string '#C0C0C0'
62
63 * "hex2rgb('hex' [,$delim])" - It's the opposite of the rgb2hex()
64 entry elsewhere in this document: takes a hexidecimal represantation
65 of a color and returns a numeric list of Red, Green and Blue. If
66 optional $delim delimiter is present, it returns the string of RGB
67 colors delimited by the $delimiter. Characters like '#' and 'Ox' in
68 the begining of the hexidecimal value will be ignored. Examples:
69
70 $hex = '#00FF00'; # represents blue
71
72 @rgb = $rgb->hex2rgb($hex); #returns list of 0, 255, 0
73 $rgb_string = $rgb->hex2rgb($hex,','); #returns string '0,255,0'
74
75 Note: the hex2rgb() entry elsewhere in this document expects valid
76 hexidecimal represantation of a color in 6 character long string. If
77 not, it might not work properly.
78
79 * "names([$pattern]" - returns a list of all the aliases in the
80 rgb.txt file. If $pattern is givven as the first argument, it will
81 return only the names matching the pattern. Example:
82
83 @grey_colors = $rgb->names; # returns all the names
84
85 @grey_colors = $rgb->names('gray'); # returns list of all the names
86 # matching the word 'gray'
87
88CREDITS
89 Following people contributed to this library with their patches and/or
90 bug reports. (list is in chronological order)
91
92 * Marc-Olivier BERNARD <mob@kilargo.fr> notified of the warnings that
93 the library produced while "warnings" pragma enabled and improper
94 parsed rgb values that contain single "0". This bug was fixed in 1.2
95
96 * "Herrmann Martin (FV/FLI) *" <Martin.Herrmann@de.bosch.com> noticed
97 a bug in rgb2hex() method which was failing if the blue value was a
98 single "0". This problem is fixed in 1.3
99
100AUTHOR
101 Sherzod B. Ruzmetov <sherzodr@cpan.org>
102
103SEE ALSO
104 the Color::Object manpage
105
106