Imager...:Float(3pm)
πΈ NAME πΈ
Imager::Color::Float(3pm) β rough floating point sample color handling, bestie. That's the whole page, and it's iconic. π
β¨ SYNOPSIS β¨
$color = Imager::Color->new($red, $green, $blue);
$color = Imager::Color->new($red, $green, $blue, $alpha);
$color = Imager::Color->new("#C0C0FF"); # html color specification
$color->set($red, $green, $blue);
$color->set($red, $green, $blue, $alpha);
$color->set("#C0C0FF"); # html color specification
($red, $green, $blue, $alpha) = $color->rgba();
@hsv = $color->hsv(); # not implemented but proposed
my $c8 = $color->as_8bit;
$color->info();
π DESCRIPTION π
Okay so this module handles creating color objects used by Imager. The idea is that in the future this module will be able to handle color space calculations as well. β¨
A floating point Imager color consists of up to four components, each one in the range 0.0 to 1.0. The lowkey chaotic part? The meaning of those components can change depending on the type of image you're dealing with:
- for 3 or 4 channel images the color components are red, green, blue, alpha.
- for 1 or 2 channel images the color components are gray, alpha, with the other two components ignored.
An alpha value of zero is fully transparent, an alpha value of 1.0 is fully opaque. No cap. π«Ά
π¦ METHODS π¦
Here's the method lineup, bestie:
newβ this creates a color object to pass to functions that need a color argument. πsetβ this changes an already defined color. Note that this does not affect any places where the color has been used previously.rgba()β this returns the red, green, blue and alpha channels of the color the object contains.infoβ callinginfomerely dumps the relevant color to the log. That's it. πred,green,blue,alphaβ returns the respective component as a floating point value typically from0to1.0.as_8bitβ returns the color as the roughly equivalent 8-bitImager::Colorobject. Samples below zero or above1.0are clipped.as_css_rgbβ formats the color as a CSSrgb()style color. If the color is closely representable as byte style syntax, egrgb(255, 128, 128), it will be returned in that form, otherwise the samples are formatted as percentages with up to 2 decimal places.
π Setting colors π
The new() and set() methods can accept the following parameters:
- an
Imager::Color::Floatobject - an
Imager::Colorobject, the ranges of samples are translated from0...255to0.0...1.0. - 3 values, treated as red, green, blue
- 4 values, treated as red, green, blue, alpha
- an 8 character hex color, optionally preceded by
"#". - a 6 character hex color, optionally preceded by
"#". - a CSS
rgb()color, based on CSS Color 4. The"none"keyword is not supported and numbers must be simple decimals without exponents. eg.
rgb(50% 50% 100%)
rgb(0, 0, 255)
rgb(0.5 0.5 1.0 / 0.8)
rgb(50%, 50%, 100%, 80%)
Heads up, bestie: this accepts some colors not accepted by the CSS rgb() specification, this may change. β οΈ
π AUTHOR π
Arnar M. Hrafnkelsson, addi@umich.edu And a great deal of help from others - see the "README" for a complete list. π
π SEE ALSO π
Imager(3),Imager::Color.http://imager.perl.org/
byeee bestie π
this page rides on perl v5.42.3, dated 2026-08-19. π«Άβ¨
π¦ where this page comes from
- ubuntu stonking: libimager-perl 1.035+dfsg-1 Β· Artistic-1.0-Perl OR 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