Imager::Color - Color handling for Imager.
Contents
Description
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.
An Imager color consists of up to four components, each in the range 0 to 255. Unfortunately the meaning
of the 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 255 is fully opaque.
Methods
hsv()
my($h, $s, $v, $alpha) = $color->hsv();
Returns the color as a Hue/Saturation/Value/Alpha tuple.
red
green
blue
alpha
Returns the respective component as an integer from 0 to 255.
as_float
Returns the color as a Imager::Color::Float object.
as_css_rgb
Returns the color as a CSS rgb() format color. This is always returned in the byte form, eg. rgb(255
128 64).
If the alpha is not full coverage (255) it will be rounded if the result of converting the color back
to an 8 bit color would return the same alpha, eg. if the color alpha is 128, it will be formatted as
0.5, not as the more precise 50.2%.
Name
Imager::Color - Color handling for Imager.
See Also
Imager(3), Imager::Color http://imager.perl.org/ perl v5.40.1 2025-03-16 Imager::Color(3pm)
Synopsis
use Imager;
$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();
$color->info();
if ($color->equals(other=>$other_color)) {
...
}
