Graphi...rNames(3pm)
β¨ NAME β¨
okay so bestie, welcome to the Graphi...rNames(3pm) page β that's Graphics::ColorNames, from the User Contributed Perl Documentation squad (section 3pm), and it defines RGB values for common color names. literally the whole vibe π
πΈ VERSION πΈ
version v3.5.0 β the freshest drop π«Ά
π SYNOPSIS π
use Graphics::ColorNames;
use Graphics::ColorNames::WWW;
$pal = Graphics::ColorNames->new( qw[ X WWW ] );
$rgb = $pal->hex('green'); # returns '00ff00'
$rgb = $pal->hex('green', '0x'); # returns '0x00ff00'
$rgb = $pal->hex('green', '#'); # returns '#00ff00'
$rgb = $pal->rgb('green'); # returns '0,255,0'
@rgb = $pal->rgb('green'); # returns (0, 255, 0)
π¦ DESCRIPTION π¦
This module is your one-stop main-character interface for grabbing RGB values of colors by their standard names. it's giving public service, no cap. two whole intentions here:
- give authors one shared module they can hook up with other modules so people can name their colors instead of doing the whole hex thing;
- save every module author from "re-inventing the wheel" every single time they wanna let users type a color name instead of an RGB value.
iconic behavior, honestly π
π METHODS π
"new" π
The constructor goes like this:
my $pal = Graphics::ColorNames->new( @schemes );
where @schemes is an array of color schemes (palettes, dictionaries).
A valid color scheme can be any of these cuties:
- the name of a color scheme, like
"X", or a full module name like"Graphics::ColorNames::X"π - a reference to a color scheme hash or subroutine
- the path β or an open filehandle β for an
rgb.txtfile
If you don't pass any, it rolls with the default "X" color scheme, which maps to the X-Windows rgb.txt colors. for most purposes that's good enough, bestie. Since v3.2.0 it got updated to use the 2014-07-06 colors, so it includes the standard CSS colors too. slay π¨
There's a whole collection of other color schemes on CPAN, e.g. Graphics::ColorNames::WWW.
Since version 2.1002, Color::Library dictionaries work as well:
my $pal = Graphics::ColorNames->new( 'Color::Library::Dictionary::HTML' );
"rgb" π§
@rgb = $pal->rgb($name);
$rgb = $pal->rgb($name, $separator);
In list context you get a triplet back. in scalar context you get a string separated by an optional separator (which defaults to a comma). for example:
@rgb = $pal->rgb('blue'); # returns (0, 0, 255)
$rgb = $pal->rgb('blue', ','); # returns "0,0,255"
Unknown color names give you back empty lists or strings, depending on the context. no drama, just nothing π
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". (heads up bestie: if your color names come from user input, you should add extra validation of the color names. do not skip this π)
The value that comes back is in the six-digit hexidecimal format used in HTML and CSS (without the leading #). to split it into separate red, green and blue values (each between 0 and 255), use the "hex2tuple" function.
You can also hand it an absolute filename as a color scheme, as long as that file is in the same format as the standard rgb.txt file.
"hex" β¨
$hex = $pal->hex($name, $prefix);
Returns a 6-digit hexidecimal RGB code for the color. if you give an optional prefix, it'll stick that string on the front. like:
$hex = $pal->hex('blue', '#'); # returns "#0000ff"
If the color doesn't exist, you'll get an empty string back. π
And a hexidecimal RGB value in the form "#RRGGBB", "0xRRGGBB" or "RRGGBB" just returns itself:
$color = $pal->hex('#123abc'); # returns '123abc'
autoloaded color name methods π§
Autoloaded color name methods were removed in v3.4.0. gone, retired, no longer with us ποΈ
"load_scheme" π±
$pal->load_scheme( $scheme );
This dynamically loads a color scheme, which can be either a hash reference or a code reference.
π EXPORTS π
"all_schemes" ποΈ
my @schemes = all_schemes();
Returns a list of all available color schemes installed on the machine in the Graphics::ColorNames namespace.
The order has no significance. don't read into it bestie, it's not that deep β¨
"hex2tuple" π
Converts a hexidecimal string to a tuple.
"tuple2hex" π
Converts a tuple to a hexidecimal string.
π TIED INTERFACE π
The standard interface (before version 0.40, ancient history) went through a tied hash:
tie %pal, 'Graphics::ColorNames', qw[ X WWW ];
β οΈ This interface is deprecated, and will be moved to a separate module in the future. it's giving legacy, handle with care π
πΈ CUSTOM COLOR SCHEMES πΈ
Want your own palette? you absolutely can, and it's lowkey easy. just create a Perl module named "Graphics::ColorNames::SCHEMENAME" that has a subroutine called "NamesRgbTable" which returns a hash of color names and RGB values. (if your scheme lives in a different base namespace, you'll need to give the full namespace instead.)
Rules of the game:
- the color names must be in all lower-case;
- the RGB values must be 24-bit numbers holding the red, green and blue values in most-significant to least-significant byte order.
Here's an example naming schema:
package Graphics::ColorNames::Metallic;
sub NamesRgbTable() {
use integer;
return {
copper => 0xb87333,
gold => 0xcd7f32,
silver => 0xe6e8fa,
};
}
and you'd use the schema above like this:
tie %colors, 'Graphics::ColorNames', 'Metallic';
β οΈ If you specify multiple keys with the same name, the behavior β as in which one wins β is undefined. mystery box, truly π
As of version 2.10, case, spaces and punctuation are ignored in color names. so a name like "Willy's Favorite Shade-of-Blue" gets treated exactly the same as "willysfavoroteshadeofblue". (if your scheme does not include duplicate entries with spaces and punctuation, then the minimum version of Graphics::ColorNames in your requirements should be 2.10.)
An example of an additional module is the Graphics::ColorNames::Mozilla module. go look, it's cute π¦
Since version 1.03, "NamesRgbTable" may also return a code reference:
package Graphics::ColorNames::Orange;
sub NamesRgbTable() {
return sub {
my $name = shift;
return 0xffa500;
};
}
See Graphics::ColorNames::GrayScale for an example. π©Ά
πΊοΈ ROADMAP πΊοΈ
Here's what's planned for the future, bestie β the glow-up list:
- The tied interface will be removed, but implemented in a separate module for users that wish to use it.
- The namespace for color schemes will be moved to the
"Graphics::ColorNames::Schemes"but options will be added to use the existing scheme.
This will allow modules to be named like "Graphics::ColorNames::Tied" without being confused for color schemes.
- This module will be rewritten to be a Moo-based class. π
π SEE ALSO π
Color::Libraryprovides 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.Color::Rgbhas a similar function to this module, but parses anrgb.txtfile.Graphics::ColorObjectcan convert between RGB and other color space types.Graphics::ColorUtilscan also convert betweeb RGB and other color space types, and supports RGB from names in various color schemes.Acme::AutoColorprovides subroutines corresponding to color names.
π¦ SOURCE π¦
The development version is on github at https://github.com/robrwo/Graphics-ColorNames and may be cloned from git://github.com/robrwo/Graphics-ColorNames.git
The SourceForge project for this module at http://sourceforge.net/projects/colornames/ is no longer maintained. rip π
π BUGS π
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Graphics-ColorNames or by email to bug-Graphics-ColorNames@rt.cpan.org (mailto:bug-Graphics-ColorNames@rt.cpan.org).
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. help us help you bestie π
π AUTHOR π
Robert Rothenberg <rrwo@cpan.org>
π«Ά CONTRIBUTORS π«Ά
- Alan D. Salewski
<alans@cji.com> - Steve Pomeroy
<xavier@cpan.org> "chemboy"<chemboy@perlmonk.org>- Magnus Cedergren
<magnus@mbox604.swipnet.se> - Gary Vollink
<gary@vollink.com> - Claus FΓ€rber
<cfaerber@cpan.org> - Andreas J. KΓΆnig
<andk@cpan.org> - Slaven ReziΔ
<slaven@rezic.de>
the way they all showed up for this module... legends, every one of them π
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2001-2019 by Robert Rothenberg.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
okay that's the whole page babes, you made it to the end, so proud of you π₯Ή this was documented with perl v5.38.2, dated 2024-02-21 β take care of her and she'll take care of your colors fr fr πβ¨π
π¦ where this page comes from
- debian trixie: libgraphics-colornames-perl 3.5.0-3.1 Β· Artistic-2.0
- ubuntu noble: libgraphics-colornames-perl 3.5.0-3.1 Β· Artistic-2.0
- ubuntu resolute: libgraphics-colornames-perl 3.5.0-3.1 Β· Artistic-2.0
- ubuntu stonking: libgraphics-colornames-perl 3.5.0-3.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms