Graphic...:Format(3)
π Graphic...:Format(3) β like, the whole vibe of acceptable color definitions
okay so real talk: this is a User Contributed Perl Documentation page for Graphics::Toolkit::Color::Manual::Format (GTC to its friends π) and it's basically the what counts as a color rulebook. π
β¨ SYNOPSIS β¨
Bestie, this whole page is a list-and-explain of every single form a color definition is allowed to take. A color definition is a piece of data that defines a color unambiguously β and from which GTC can build a color object. π
And here's the GTC philosophy, no cap: every format that can be read should also be produced as output, and vice versa. The way that it's a whole two-way street. π¦
There is exactly one exception to that principle: the list and array formats. Values from any color space can be written in these formats, but when they get read, RGB is assumed β because there's literally no attached info about the color space. π
There's a quick overview of all the formats over here too. π
This page is especially important to understand the capabilities of the methodsnewandvalues. π«Ά
π FORMATS π
π name
The format name is a color name string, like:
'blue'
and a full_name also contains a color scheme name, like in:
'SVG:green'
Read all about them under "SYNTAX" in Graphics::Toolkit::Color::Manual::Name. π
They get read by the constructor, but written by name and closest_name. And over there you can hand over the argument full to get a full name. slay.
π hex_string
A hex_string starts with the pound sign '#', followed by three digits (that's the short version) or six digits (the long version) β hexadecimal, and they might be written in upper or lower case, whatever, we don't judge. πΈ It always depicts an RGB color.
The following examples represent the same color:
'#123'
'#112233'
π named_string
named_string is GTC's own simple string format for data serialisation. π
Similar to a full_name, it has the color space name on the left side of the colon β lower case, no special characters allowed. Then right of the colon live the comma separated values. Placement of any whitespace is optional, but the commas are not. Also optional: value suffixes like '%' in HWB. β¨
'rgb: 1, 2, 3'
π css_string
css_string is a format standardized by the W3C, and it's closely related to a named_string with a few important differences. π
Here, the commas and the suffix are optional. But β plot twist π β if you omit the commas, you have to separate the values by whitespace. And the values have to be encompassed by round braces. Also, fyi: GTC does not yet support a css_string that includes an alpha channel. π
'rgb( 1, 2, 3)'
π list
list is the default format of the values method. It's just simply a list with the color values, and they follow the same order as the axis names. π¦
If it's used as an input, GTC reads them as standard RGB values.
(1,2,3)
π array
array is just a list inside square brackets (an ARRAY reference), so like, almost the same rules apply as for list β it's read as RGB by default. π
This format has one sole advantage over a list: from a Perl perspective it's a scalar, so it can be used for an argument like to in methods like distance. Iconic. π
You may use it for values in other spaces too β but then you have to provide the space name via the argument in.
[1,2,3]
π named_array
named_array fixes the disadvantage of the array format by prepending the color space name in front of the values. π§
Color space names can be written with a great degree of freedom, which is explained here. And please note the usage of a fat comma, for your own convenience. Both examples are semantically identical. π
[ RGB => 1,2,3 ]
['RGB', 1,2,3 ]
π nested_array
nested_array is just a variation on a named_array, where the values are enclosed in another ARRAY reference. To some people it just makes intuitively more sense. πΈ
[RGB => [1,2,3]]
π hash
hash is the most expressive and spacious format. It's a HASH reference with long axis names as keys. π
It requires all axes to be presented by name β even if GTC will accept any mix of long and short axis names. And if you order hash as the output format, you will get long axis names only. β¨
The biggest downside of this format is its ambiguity, especially because GTC supports over 10 RGB spaces. π Please read about the search order to see which spaces get overshadowed by others, and how. In short: look at the name of a color space family to see which space is dominant. If you want to define a color in a color space that is not dominant, you have to either use another format that contains the color space name, or provide the space name via the argument in. π
{red => 1, green => 2, blue => 3}
π char_hash
char_hash is the format name that makes sure the output of values is a HASH with short axis names as keys. Other than that? It's the same as hash. π«Ά
{r => 1, g => 2, b => 3}
π AUTHOR π
Herbert Breunung, <lichtkind@cpan.org> π
π COPYRIGHT π
Copyright 2026 Herbert Breunung.
π₯ LICENSE π₯
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. periodt. π
okay that's the whole page bestie β brought to you by perl v5.42.2, dated 2026-06-21, from the one and only Graphic...:Format(3). go forth and define colors unambiguously πβ¨ππ¦
π¦ where this page comes from
- arch rolling: perl-graphics-toolkit-color 2.22-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms