.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" 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 .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . 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 .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Graphics::ColorNames 3pm" .TH Graphics::ColorNames 3pm "2017-01-12" "perl v5.24.1" "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 "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Graphics::ColorNames 2.10; \& \& $po = new Graphics::ColorNames(qw( X )); \& \& $rgb = $po\->hex(\*(Aqgreen\*(Aq); # returns \*(Aq00ff00\*(Aq \& $rgb = $po\->hex(\*(Aqgreen\*(Aq, \*(Aq0x\*(Aq); # returns \*(Aq0x00ff00\*(Aq \& $rgb = $po\->hex(\*(Aqgreen\*(Aq, \*(Aq#\*(Aq); # returns \*(Aq#00ff00\*(Aq \& \& $rgb = $po\->rgb(\*(Aqgreen\*(Aq); # returns \*(Aq0,255,0\*(Aq \& @rgb = $po\->rgb(\*(Aqgreen\*(Aq); # returns (0, 255, 0) \& \& $rgb = $po\->green; # same as $po\->hex(\*(Aqgreen\*(Aq); \& \& tie %ph, \*(AqGraphics::ColorNames\*(Aq, (qw( X )); \& \& $rgb = $ph{green}; # same as $po\->hex(\*(Aqgreen\*(Aq); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module provides a common interface for obtaining the \s-1RGB\s0 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 \*(L"re-invent the wheel\*(R" whenever they decide to give the users the option of specifying a color by name rather than \s-1RGB\s0 value. .PP For example, .PP .Vb 1 \& use Graphics::ColorNames 2.10; \& \& use GD; \& \& $pal = new Graphics::ColorNames; \& \& $img = new GD::Image(100, 100); \& \& $bgColor = $img\->colorAllocate( $pal\->rgb(\*(AqCadetBlue3\*(Aq) ); .Ve .PP Although this is a little \*(L"bureaucratic\*(R", the meaning of this code is clear: \&\f(CW$bgColor\fR (or background color) is 'CadetBlue3' (which is easier to for one to understand than \f(CW\*(C`0x7A, 0xC5, 0xCD\*(C'\fR). The variable is named for its function, not form (ie, \f(CW$CadetBlue3\fR) so that if the author later changes the background color, the variable name need not be changed. .PP You can also define \*(L"Custom Color Schemes\*(R" for specialised palettes for websites or institutional publications: .PP .Vb 1 \& $color = $pal\->hex(\*(AqMenuBackground\*(Aq); .Ve .PP As an added feature, a hexidecimal \s-1RGB\s0 value in the form of #RRGGBB, 0xRRGGBB or \s-1RRGGBB\s0 will return itself: .PP .Vb 1 \& $color = $pal\->hex(\*(Aq#123abc\*(Aq); # returns \*(Aq123abc\*(Aq .Ve .SS "Tied Interface" .IX Subsection "Tied Interface" The standard interface (prior to version 0.40) is through a tied hash: .PP .Vb 1 \& tie %pal, \*(AqGraphics::ColorNames\*(Aq, @schemes; .Ve .PP where \f(CW%pal\fR is the tied hash and \f(CW@schemes\fR is a list of color schemes. .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 As of version 2.1002, one can also use Color::Library dictionaries: .PP .Vb 1 \& tie %pal, \*(AqGraphics::ColorNames\*(Aq, qw(Color::Library::Dictionary::HTML); .Ve .PP This is an experimental feature which may change in later versions (see \&\*(L"\s-1SEE ALSO\*(R"\s0 for a discussion of the differences between modules). .PP Multiple schemes can be used: .PP .Vb 1 \& tie %pal, \*(AqGraphics::ColorNames\*(Aq, qw(HTML Netscape); .Ve .PP In this case, if the name is not a valid \s-1HTML\s0 color, the Netscape name will be used. .PP One can load all available schemes in the Graphics::ColorNames namespace (as of version 2.0): .PP .Vb 2 \& use Graphics::ColorNames 2.0, \*(Aqall_schemes\*(Aq; \& tie %NameTable, \*(AqGraphics::ColorNames\*(Aq, all_schemes(); .Ve .PP When multiple color schemes define the same name, then the earlier one listed has priority (however, hash-based color schemes always have priority over code-based color schemes). .PP When no color scheme is specified, the X\-Windows scheme is assumed. .PP Color names are case insensitive, and spaces or punctuation are ignored. So \*(L"Alice Blue\*(R" returns the same value as \*(L"aliceblue\*(R", \*(L"ALICE-BLUE\*(R" and \*(L"a*lICEbl\-ue\*(R". (If you are using color names based on user input, you may want to add additional validation of the color names.) .PP The value returned is in the six-digit hexidecimal format used in \s-1HTML\s0 and \&\s-1CSS \s0(without the initial '#'). To convert it to separate red, green, and blue values (between 0 and 255), use the \*(L"hex2tuple\*(R" function. .SS "Object-Oriented Interface" .IX Subsection "Object-Oriented Interface" If you prefer, an object-oriented interface is available: .PP .Vb 1 \& use Graphics::ColorNames 0.40; \& \& $obj = Graphics::ColorNames\->new(\*(Aq/etc/rgb.txt\*(Aq); \& \& $hex = $obj\->hex(\*(Aqskyblue\*(Aq); # returns "87ceeb" \& @rgb = $obj\->rgb(\*(Aqskyblue\*(Aq); # returns (0x87, 0xce, 0xeb) .Ve .PP The interface is similar to the Color::Rgb module: .IP "new" 4 .IX Item "new" .Vb 1 \& $obj = Graphics::ColorNames\->new( @SCHEMES ); .Ve .Sp Creates the object, using the default color schemes. If none are specified, it uses the \f(CW\*(C`X\*(C'\fR scheme. .IP "load_scheme" 4 .IX Item "load_scheme" .Vb 1 \& $obj\->load_scheme( $scheme ); .Ve .Sp Loads a scheme dynamically. The scheme may be any hash or code reference. .IP "hex" 4 .IX Item "hex" .Vb 1 \& $hex = $obj\->hex($name, $prefix); .Ve .Sp Returns a 6\-digit hexidecimal \s-1RGB\s0 code for the color. If an optional prefix is specified, it will prefix the code with that string. For example, .Sp .Vb 1 \& $hex = $obj\->hex(\*(Aqblue\*(Aq, \*(Aq#\*(Aq); # returns "#0000ff" .Ve .IP "rgb" 4 .IX Item "rgb" .Vb 1 \& @rgb = $obj\->rgb($name); \& \& $rgb = $obj\->rgb($name, $separator); .Ve .Sp If called in a list context, returns a triplet. .Sp If called in a scalar context, returns a string separated by an optional separator (which defauls to a comma). For example, .Sp .Vb 1 \& @rgb = $obj\->rgb(\*(Aqblue\*(Aq); # returns (0, 0, 255) \& \& $rgb = $obj\->rgb(\*(Aqblue\*(Aq, \*(Aq,\*(Aq); # returns "0,0,255" .Ve .PP Since version 2.10_02, the interface will assume method names are color names and return the hex value, .PP .Vb 1 \& $obj\->black eq $obj\->hex("black") .Ve .PP Method names are case-insensitive, and underscores are ignored. .SS "Utility Functions" .IX Subsection "Utility Functions" These functions are not exported by default, so much be specified to be used: .PP .Vb 1 \& use Graphics::ColorNames qw( all_schemes hex2tuple tuple2hex ); .Ve .IP "all_schemes" 4 .IX Item "all_schemes" .Vb 1 \& @schemes = all_schemes(); .Ve .Sp Returns a list of all available color schemes installed on the machine in the \fIGraphics::ColorNames\fR namespace. .Sp The order has no significance. .IP "hex2tuple" 4 .IX Item "hex2tuple" .Vb 1 \& ($red, $green, $blue) = hex2tuple( $colors{\*(AqAliceBlue\*(Aq}); .Ve .IP "tuple2hex" 4 .IX Item "tuple2hex" .Vb 1 \& $rgb = tuple2hex( $red, $green, $blue ); .Ve .SS "Color Schemes" .IX Subsection "Color Schemes" The following schemes are available by default: .IP "X" 4 .IX Item "X" About 750 color names used in X\-Windows (although about 90+ of them are duplicate names with spaces). .IP "\s-1HTML\s0" 4 .IX Item "HTML" 16 common color names defined in the \s-1HTML 4.0\s0 specification. These names are also used with older \s-1CSS\s0 and \s-1SVG\s0 specifications. (You may want to see Graphics::ColorNames::SVG for a complete list.) .IP "Netscape" 4 .IX Item "Netscape" 100 color names names associated Netscape 1.1 (I cannot determine whether they were once usable in Netscape or were arbitrary names for \s-1RGB\s0 values\*(-- many of these names are not recognized by later versions of Netscape). .Sp This scheme may be deprecated in future versions, but available as a separate module. .IP "Windows" 4 .IX Item "Windows" 16 commom color names used with Microsoft Windows and related products. These are actually the same colors as the \*(L"\s-1HTML\*(R"\s0 scheme, although with different names. .PP Rather than a color scheme, the path or open filehandle for a \&\fIrgb.txt\fR file may be specified. .PP Additional color schemes may be available on \s-1CPAN.\s0 .SS "Custom Color Schemes" .IX Subsection "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 \s-1RGB\s0 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 \s-1RGB\s0 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 \*(L"Willy's Favorite Shade-of-Blue\*(R" is treated the same as \*(L"willysfavoroteshadeofblue\*(R". (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 by Steve Pomeroy. .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. .SS "Graphics::ColourNames" .IX Subsection "Graphics::ColourNames" The alias \*(L"Graphics::ColourNames\*(R" (British spelling) is no longer available as of version 2.01. .PP It seems absurd to maintain it when all the modules does is provide an alternative spelling for the module \fIname\fR without doing anything about the component colors of each scheme, and when most other modules (and non-Perl software) does not bother with such things. .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 \s-1RGB\s0 and other color space types. .PP Acme::AutoColor provides subroutines corresponding to color names. .SH "AUTHOR" .IX Header "AUTHOR" Robert Rothenberg .SS "Acknowledgements" .IX Subsection "Acknowledgements" Alan D. Salewski for feedback and the addition of \&\f(CW\*(C`tuple2hex\*(C'\fR. .PP Steve Pomeroy , \*(L"chemboy\*(R" and \*(L"magnus\*(R" who pointed out issues with various color schemes. .SS "Suggestions and Bug Reporting" .IX Subsection "Suggestions and Bug Reporting" Feedback is always welcome. Please use the \s-1CPAN\s0 Request Tracker at to submit bug reports. .PP There is a Sourceforge project for this package at . .PP If you create additional color schemes, please make them available separately in \s-1CPAN\s0 rather than submit them to me for inclusion into this module. .SH "LICENSE" .IX Header "LICENSE" Copyright (c) 2001\-2008 Robert Rothenberg. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.