.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Graphics::ColorNames 3pm" .TH Graphics::ColorNames 3pm 2024-02-21 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Graphics::ColorNames \- defines RGB values for common color names .SH VERSION .IX Header "VERSION" version v3.5.0 .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 2 \& use Graphics::ColorNames; \& use Graphics::ColorNames::WWW; \& \& $pal = Graphics::ColorNames\->new( qw[ X WWW ] ); \& \& $rgb = $pal\->hex(\*(Aqgreen\*(Aq); # returns \*(Aq00ff00\*(Aq \& $rgb = $pal\->hex(\*(Aqgreen\*(Aq, \*(Aq0x\*(Aq); # returns \*(Aq0x00ff00\*(Aq \& $rgb = $pal\->hex(\*(Aqgreen\*(Aq, \*(Aq#\*(Aq); # returns \*(Aq#00ff00\*(Aq \& \& $rgb = $pal\->rgb(\*(Aqgreen\*(Aq); # returns \*(Aq0,255,0\*(Aq \& @rgb = $pal\->rgb(\*(Aqgreen\*(Aq); # returns (0, 255, 0) .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" This module provides a common interface for obtaining the RGB values of colors by standard names. The intention is to (1) provide a common module that authors can use with other modules to specify colors by name; and (2) free module authors from having to "re-invent the wheel" whenever they decide to give the users the option of specifying a color by name rather than RGB value. .SH METHODS .IX Header "METHODS" .ie n .SS """new""" .el .SS \f(CWnew\fP .IX Subsection "new" The constructor is as follows: .PP .Vb 1 \& my $pal = Graphics::ColorNames\->new( @schemes ); .Ve .PP where \f(CW@schemes\fR is an array of color schemes (palettes, dictionaries). .PP A valid color scheme may be the name of a color scheme (such as \f(CW\*(C`X\*(C'\fR or a full module name such as \f(CW\*(C`Graphics::ColorNames::X\*(C'\fR), a reference to a color scheme hash or subroutine, or to the path or open filehandle for a \fIrgb.txt\fR file. .PP If none are specified, it uses the default \f(CW\*(C`X\*(C'\fR color scheme, which corresponds to the X\-Windows \fIrgb.txt\fR colors. For most purposes, this is good enough. Since v3.2.0, it was updated to use the 2014\-07\-06 colors, so includes the standard CSS colors as well. .PP Other color schemes are available on CPAN, e.g. Graphics::ColorNames::WWW. .PP Since version 2.1002, Color::Library dictionaries can be used as well: .PP .Vb 1 \& my $pal = Graphics::ColorNames\->new( \*(AqColor::Library::Dictionary::HTML\*(Aq ); .Ve .ie n .SS """rgb""" .el .SS \f(CWrgb\fP .IX Subsection "rgb" .Vb 1 \& @rgb = $pal\->rgb($name); \& \& $rgb = $pal\->rgb($name, $separator); .Ve .PP If called in a list context, returns a triplet. .PP If called in a scalar context, returns a string separated by an optional separator (which defauls to a comma). For example, .PP .Vb 1 \& @rgb = $pal\->rgb(\*(Aqblue\*(Aq); # returns (0, 0, 255) \& \& $rgb = $pal\->rgb(\*(Aqblue\*(Aq, \*(Aq,\*(Aq); # returns "0,0,255" .Ve .PP Unknown color names return empty lists or strings, depending on the context. .PP Color names are case insensitive, and spaces or punctuation are ignored. So "Alice Blue" returns the same value as "aliceblue", "ALICE-BLUE" and "a*lICEbl\-ue". (If you are using color names based on user input, you should add additional validation of the color names.) .PP The value returned is in the six-digit hexidecimal format used in HTML and CSS (without the initial '#'). To convert it to separate red, green, and blue values (between 0 and 255), use the "hex2tuple" function. .PP You may also specify an absolute filename as a color scheme, if the file is in the same format as the standard \fIrgb.txt\fR file. .ie n .SS """hex""" .el .SS \f(CWhex\fP .IX Subsection "hex" .Vb 1 \& $hex = $pal\->hex($name, $prefix); .Ve .PP Returns a 6\-digit hexidecimal RGB code for the color. If an optional prefix is specified, it will prefix the code with that string. For example, .PP .Vb 1 \& $hex = $pal\->hex(\*(Aqblue\*(Aq, \*(Aq#\*(Aq); # returns "#0000ff" .Ve .PP If the color does not exist, it will return an empty string. .PP A hexidecimal RGB value in the form of \f(CW\*(C`#RRGGBB\*(C'\fR, \f(CW\*(C`0xRRGGBB\*(C'\fR or \&\f(CW\*(C`RRGGBB\*(C'\fR will return itself: .PP .Vb 1 \& $color = $pal\->hex(\*(Aq#123abc\*(Aq); # returns \*(Aq123abc\*(Aq .Ve .SS "autoloaded color name methods" .IX Subsection "autoloaded color name methods" Autoloaded color name methods were removed in v3.4.0. .ie n .SS """load_scheme""" .el .SS \f(CWload_scheme\fP .IX Subsection "load_scheme" .Vb 1 \& $pal\->load_scheme( $scheme ); .Ve .PP This dynamically loads a color scheme, which can be either a hash reference or code reference. .SH EXPORTS .IX Header "EXPORTS" .ie n .SS """all_schemes""" .el .SS \f(CWall_schemes\fP .IX Subsection "all_schemes" .Vb 1 \& my @schemes = all_schemes(); .Ve .PP Returns a list of all available color schemes installed on the machine in the \fIGraphics::ColorNames\fR namespace. .PP The order has no significance. .ie n .SS """hex2tuple""" .el .SS \f(CWhex2tuple\fP .IX Subsection "hex2tuple" Converts a hexidecimal string to a tuple. .ie n .SS """tuple2hex""" .el .SS \f(CWtuple2hex\fP .IX Subsection "tuple2hex" Converts a tuple to a hexidecimal string. .SH "TIED INTERFACE" .IX Header "TIED INTERFACE" The standard interface (prior to version 0.40) was through a tied hash: .PP .Vb 1 \& tie %pal, \*(AqGraphics::ColorNames\*(Aq, qw[ X WWW ]; .Ve .PP This interface is deprecated, and will be moved to a separate module in the future. .SH "CUSTOM COLOR SCHEMES" .IX Header "CUSTOM COLOR SCHEMES" You can add naming scheme files by creating a Perl module is the name \&\f(CW\*(C`Graphics::ColorNames::SCHEMENAME\*(C'\fR which has a subroutine named \&\f(CW\*(C`NamesRgbTable\*(C'\fR that returns a hash of color names and RGB values. (Schemes with a different base namespace will require the fill namespace to be given.) .PP The color names must be in all lower-case, and the RGB values must be 24\-bit numbers containing the red, green, and blue values in most\- significant to least\- significant byte order. .PP An example naming schema is below: .PP .Vb 1 \& package Graphics::ColorNames::Metallic; \& \& sub NamesRgbTable() { \& use integer; \& return { \& copper => 0xb87333, \& gold => 0xcd7f32, \& silver => 0xe6e8fa, \& }; \& } .Ve .PP You would use the above schema as follows: .PP .Vb 1 \& tie %colors, \*(AqGraphics::ColorNames\*(Aq, \*(AqMetallic\*(Aq; .Ve .PP The behavior of specifying multiple keys with the same name is undefined as to which one takes precedence. .PP As of version 2.10, case, spaces and punctuation are ignored in color names. So a name like "Willy's Favorite Shade-of-Blue" is treated the same as "willysfavoroteshadeofblue". (If your scheme does not include duplicate entrieswith spaces and punctuation, then the minimum version of Graphics::ColorNames should be 2.10 in your requirements.) .PP An example of an additional module is the Graphics::ColorNames::Mozilla module. .PP Since version 1.03, \f(CW\*(C`NamesRgbTable\*(C'\fR may also return a code reference: .PP .Vb 1 \& package Graphics::ColorNames::Orange; \& \& sub NamesRgbTable() { \& return sub { \& my $name = shift; \& return 0xffa500; \& }; \& } .Ve .PP See Graphics::ColorNames::GrayScale for an example. .SH ROADMAP .IX Header "ROADMAP" The following changes are planned in the future: .IP \(bu 4 The tied interface will be removed, but implemented in a separate module for users that wish to use it. .IP \(bu 4 The namespace for color schemes will be moved to the \&\f(CW\*(C`Graphics::ColorNames::Schemes\*(C'\fR but options will be added to use the existing scheme. .Sp This will allow modules to be named like \f(CW\*(C`Graphics::ColorNames::Tied\*(C'\fR without being confused for color schemes. .IP \(bu 4 This module will be rewritten to be a Moo\-based class. .SH "SEE ALSO" .IX Header "SEE ALSO" Color::Library provides an extensive library of color schemes. A notable difference is that it supports more complex schemes which contain additional information about individual colors and map multiple colors to a single name. .PP Color::Rgb has a similar function to this module, but parses an \&\fIrgb.txt\fR file. .PP Graphics::ColorObject can convert between RGB and other color space types. .PP Graphics::ColorUtils can also convert betweeb RGB and other color space types, and supports RGB from names in various color schemes. .PP Acme::AutoColor provides subroutines corresponding to color names. .SH SOURCE .IX Header "SOURCE" The development version is on github at and may be cloned from .PP The SourceForge project for this module at is no longer maintained. .SH BUGS .IX Header "BUGS" Please report any bugs or feature requests on the bugtracker website or by email to bug\-Graphics\-ColorNames@rt.cpan.org . .PP When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. .SH AUTHOR .IX Header "AUTHOR" Robert Rothenberg .SH CONTRIBUTORS .IX Header "CONTRIBUTORS" .IP \(bu 4 Alan D. Salewski .IP \(bu 4 Steve Pomeroy .IP \(bu 4 "chemboy" .IP \(bu 4 Magnus Cedergren .IP \(bu 4 Gary Vollink .IP \(bu 4 Claus Färber .IP \(bu 4 Andreas J. König .IP \(bu 4 Slaven Rezić .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is Copyright (c) 2001\-2019 by Robert Rothenberg. .PP This is free software, licensed under: .PP .Vb 1 \& The Artistic License 2.0 (GPL Compatible) .Ve