1Color::Library::Color(3U)ser Contributed Perl DocumentatiCoonlor::Library::Color(3)
2
3
4

NAME

6       Color::Library::Color - Color entry for a Color::Library color
7       dictionary
8

METHODS

10       $id = $color->id
11           Returns the id of the color
12
13           A color id is in the format of <dictionary_id:color_name>, e.g.
14
15               svg:aliceblue
16               x11:bisque2
17               nbs-iscc-f:chromeyellow.66
18               vaccc:darkspringyellow
19
20       $name = $color->name
21           Returns the name of the color, e.g.
22
23               aliceblue
24               bisque2
25               chromeyellow
26               darkspringyellow
27
28       $title = $color->title
29           Returns the title of the color, e.g.
30
31               aliceblue
32               bisque2
33               chrome yellow
34               Dark Spring-Yellow
35
36       $dictionary = $color->dictionary
37           Returns the Color::Library::Dictionary object that the color
38           belongs to
39
40       $hex = $color->hex
41           Returns the hex value of the color, e.g.
42
43               ff08ff
44               eed5b7
45               eaa221
46               669900
47
48           Note that $hex does NOT include the leading #, for that use
49           $color->html, $color->css, or $color->svg
50
51       $html = $color->html
52       $css = $color->css
53       $svg = $color->svg
54           Returns the hex value of the color with a leading #, suitable for
55           use in HTML, CSS, or SVG documents, e.g.
56
57               #ff08ff
58               #eed5b7
59               #eaa221
60               #669900
61
62       $value = $color->value
63           Returns the numeric value of the color, e.g.
64
65               15792383
66               15652279
67               15376929
68               6723840
69
70       ($r, $g, $b) = $color->rgb
71           Returns r, g, and b values of the color as a 3 element list (list
72           context), e.g.
73
74               (240, 248, 255)
75
76       $rgb = $color->rgb
77           Returns r, g, and b values of the color in a 3 element array
78           (scalar context), e.g.
79
80               [ 240, 248, 255 ]
81
82       $color = Color::Library::Color->new( id => $id, name => $name, title =>
83       $title, value => $value )
84       $color = Color::Library::Color->new( { id => $id, name => $name, title
85       => $title, value => $value } )
86       $color = Color::Library::Color->new( [[ $id, $name, $title, $rgb, $hex,
87       $value ]] )
88           Returns a new Color::Library::Color object representing the
89           specified color
90
91           You probably don't want/need to call this yourself
92
93   FUNCTIONS
94       $hex = Color::Library::Color::rgb2hex( $rgb )
95       $hex = Color::Library::Color::rgb2hex( $r, $g, $b )
96           Converts an rgb value to its hex representation
97
98       $value = Color::Library::Color::rgb2value( $rgb )
99       $value = Color::Library::Color::rgb2value( $r, $g, $b )
100           Converts an rgb value to its numeric representation
101
102       $rgb = Color::Library::Color::value2rgb( $value )
103       ($r, $g, $b) = Color::Library::Color::value2rgb( $value )
104           Converts a numeric color value to its rgb representation
105
106       ($r, $g, $b) = Color::Library::Color::parse_rgb_color( $hex )
107       ($r, $g, $b) = Color::Library::Color::parse_rgb_color( $value )
108           Makes a best effort to convert a hex or numeric color value to its
109           rgb representation
110
111       # Partly taken from Imager/Color.pm sub parse_rgb_color {
112           return (@_) if @_ == 3 && ! grep /[^\d.+eE-]/, @_;
113           if ($_[0] =~
114       /^\#?([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])$/i) {
115               return (hex($1), hex($2), hex($3));
116           }
117           if ($_[0] =~ /^\#?([\da-f])([\da-f])([\da-f])$/i) {
118               return (hex($1) * 17, hex($2) * 17, hex($3) * 17);
119           }
120           return value2rgb $_[0] if 1 == @_ && $_[0] =~ m/^\d+$/; }
121
122       1;
123
124       __END__
125
126       sub parse_rgbs_color {
127           return (@_) if @_ == 3 && ! grep /[^\d.+eE-]/, @_;
128           if ($_[0] =~
129       /^\#?([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/i)
130       {
131               return (hex($1), hex($2), hex($3), hex($4));
132           }
133           if ($_[0] =~
134       /^\#?([\da-f][\da-f])([\da-f][\da-f])([\da-f][\da-f])/i) {
135               return (hex($1), hex($2), hex($3), 255);
136           }
137           if ($_[0] =~ /^\#([\da-f])([\da-f])([\da-f])$/i) {
138               return (hex($1) * 17, hex($2) * 17, hex($3) * 17, 255);
139           }
140           return value2rgb $_[0] if 1 == @_; }
141
142
143
144perl v5.30.1                      2020-01-29          Color::Library::Color(3)
Impressum