1Imager::Color(3) User Contributed Perl Documentation Imager::Color(3)
2
3
4
6 Imager::Color - Color handling for Imager.
7
9 $color = Imager::Color->new($red, $green, $blue);
10 $color = Imager::Color->new($red, $green, $blue, $alpha);
11 $color = Imager::Color->new("#C0C0FF"); # html color specification
12
13 $color->set($red, $green, $blue);
14 $color->set($red, $green, $blue, $alpha);
15 $color->set("#C0C0FF"); # html color specification
16
17 ($red, $green, $blue, $alpha) = $color->rgba();
18 @hsv = $color->hsv(); # not implemented but proposed
19
20 $color->info();
21
22 if ($color->equals(other=>$other_color)) {
23 ...
24 }
25
27 This module handles creating color objects used by imager. The idea is
28 that in the future this module will be able to handle colorspace calcu‐
29 lations as well.
30
31 An Imager color consists of up to four components, each in the range 0
32 to 255. Unfortunately the meaning of the components can change depend‐
33 ing on the type of image you're dealing with:
34
35 · for 3 or 4 channel images the color components are red, green,
36 blue, alpha.
37
38 · for 1 or 2 channel images the color components are gray, alpha,
39 with the other two components ignored.
40
41 An alpha value of zero is fully transparent, an alpha value of 255 is
42 fully opaque.
43
45 new This creates a color object to pass to functions that need a color
46 argument.
47
48 set This changes an already defined color. Note that this does not
49 affect any places where the color has been used previously.
50
51 rgba
52 This returns the rgba code of the color the object contains.
53
54 info
55 Calling info merely dumps the relevant colorcode to the log.
56
57 equals(other=>$other_color)
58 equals(other=>$other_color, ignore_alpha=>1)
59 Compares $self and color $other_color returning true if the color
60 components are the same.
61
62 Compares all four channels unless "ignore_alpha" is set. If
63 "ignore_alpha" is set only the first three channels are compared.
64
65 You can specify colors in several different ways, you can just supply
66 simple values:
67
68 · simple numeric parameters - if you supply 3 or 4 numeric arguments,
69 you get a color made up of those RGB (and possibly A) components.
70
71 · a six hex digit web color, either 'RRGGBB' or '#RRGGBB'
72
73 · an eight hex digit web color, either 'RRGGBBAA' or '#RRGGBBAA'.
74
75 · a 3 hex digit web color, '#RGB' - a value of F becomes 255.
76
77 · a color name, from whichever of the gimp Named_Colors file or X
78 rgb.txt is found first. The same as using the name keyword.
79
80 You can supply named parameters:
81
82 · 'red', 'green' and 'blue', optionally shortened to 'r', 'g' and
83 'b'. The color components in the range 0 to 255.
84
85 # all of the following are equivalent
86 my $c1 = Imager::Color->new(red=>100, blue=>255, green=>0);
87 my $c2 = Imager::Color->new(r=>100, b=>255, g=>0);
88 my $c3 = Imager::Color->new(r=>100, blue=>255, g=>0);
89
90 · 'hue', 'saturation' and 'value', optionally shortened to 'h', 's'
91 and 'v', to specify a HSV color. 0 <= hue < 360, 0 <= s <= 1 and 0
92 <= v <= 1.
93
94 # the same as RGB(127,255,127)
95 my $c1 = Imager::Color->new(hue=>120, v=>1, s=>0.5);
96 my $c1 = Imager::Color->new(hue=>120, value=>1, saturation=>0.5);
97
98 · 'web', which can specify a 6 or 3 hex digit web color, in any of
99 the forms '#RRGGBB', '#RGB', 'RRGGBB' or 'RGB'.
100
101 my $c1 = Imager::Color->new(web=>'#FFC0C0'); # pale red
102
103 · 'gray' or 'grey' which specifies a single channel, from 0 to 255.
104
105 # exactly the same
106 my $c1 = Imager::Color->new(gray=>128);
107 my $c1 = Imager::Color->new(grey=>128);
108
109 · 'rgb' which takes a 3 member arrayref, containing each of the red,
110 green and blue values.
111
112 # the same
113 my $c1 = Imager::Color->new(rgb=>[255, 100, 0]);
114 my $c1 = Imager::Color->new(r=>255, g=>100, b=>0);
115
116 · 'hsv' which takes a 3 member arrayref, containting each of hue,
117 saturation and value.
118
119 # the same
120 my $c1 = Imager::Color->new(hsv=>[120, 0.5, 1]);
121 my $c1 = Imager::Color->new(hue=>120, v=>1, s=>0.5);
122
123 · 'gimp' which specifies a color from a GIMP palette file. You can
124 specify the filename of the palette file with the 'palette' parame‐
125 ter, or let Imager::Color look in various places, typically
126 "$HOME/gimp-1.x/palettes/Named_Colors" with and without the version
127 number, and in /usr/share/gimp/palettes/. The palette file must
128 have color names.
129
130 my $c1 = Imager::Color->new(gimp=>'snow');
131 my $c1 = Imager::Color->new(gimp=>'snow', palette=>'testimg/test_gimp_pal);
132
133 · 'xname' which specifies a color from an X11 rgb.txt file. You can
134 specify the filename of the rgb.txt file with the 'palette' parame‐
135 ter, or let Imager::Color look in various places, typically
136 '/usr/lib/X11/rgb.txt'.
137
138 my $c1 = Imager::Color->new(xname=>'blue') # usually RGB(0, 0, 255)
139
140 · 'builtin' which specifies a color from the built-in color table in
141 Imager::Color::Table. The colors in this module are the same as
142 the default X11 rgb.txt file.
143
144 my $c1 = Imager::Color->new(builtin=>'black') # always RGB(0, 0, 0)
145
146 · 'name' which specifies a name from either a GIMP palette, an X
147 rgb.txt file or the built-in color table, whichever is found first.
148
149 · 'channel0', 'channel1', etc, each of which specifies a single chan‐
150 nel. These can be abbreviated to 'c0', 'c1' etc.
151
152 · 'channels' which takes an arrayref of the channel values.
153
154 Optionally you can add an alpha channel to a color with the 'alpha' or
155 'a' parameter.
156
157 These color specifications can be used for both constructing new colors
158 with the new() method and modifying existing colors with the set()
159 method.
160
162 Arnar M. Hrafnkelsson, addi@umich.edu And a great deal of help from
163 others - see the README for a complete list.
164
166 Imager(3), Imager::Color http://imager.perl.org/
167
168
169
170perl v5.8.8 2008-03-28 Imager::Color(3)