Graphic...:Format(3)

πŸ“¦ version 2.22, in arch rolling

πŸ’… 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 methods new and values. 🫢

🌈 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 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