HomeImagickImagickDrawImagickPixelImagick Pixel IteratorImagick KernelTutorial Source codeReport an issue
Category
Example

get color value

← getColorCount   getColorValueQuantum →
Retrieves the value of the color channel specified, as a floating-point number between 0 and 1.
Alpha value is 0.75

Red value is 0.9
Green value is 0.2
Blue value is 0.2

Cyan value is 0.9
Magenta value is 0.2
Yellow value is 0.2
Black value is 0
// Example 1 - Quantum
$color = new \ImagickPixel('rgb(128, 5, 255)');
$colorRed = $color->getColorValueQuantum(\Imagick::COLOR_RED);
$colorGreen = $color->getColorValueQuantum(\Imagick::COLOR_GREEN);
$colorBlue = $color->getColorValueQuantum(\Imagick::COLOR_BLUE);
$colorAlpha = $color->getColorValueQuantum(\Imagick::COLOR_ALPHA);
return sprintf(
    "Red: %s Green: %s  Blue %s Alpha: %s",
    $colorRed,
    $colorGreen,
    $colorBlue,
    $colorAlpha
);
// Example 2
$color = new \ImagickPixel('rgba(90%, 20%, 20%, 0.75)');
$output =  "Alpha value is " . $color->getColorValue(\Imagick::COLOR_ALPHA) . "<br/>";
$output .=  "" . "<br/>";
$output .=  "Red value is " . $color->getColorValue(\Imagick::COLOR_RED) . "<br/>";
$output .=  "Green value is " . $color->getColorValue(\Imagick::COLOR_GREEN) . "<br/>";
$output .=  "Blue value is " . $color->getColorValue(\Imagick::COLOR_BLUE) . "<br/>";
$output .=  "" . "<br/>";
$output .=  "Cyan value is " . $color->getColorValue(\Imagick::COLOR_CYAN) . "<br/>";
$output .=  "Magenta value is " . $color->getColorValue(\Imagick::COLOR_MAGENTA) . "<br/>";
$output .=  "Yellow value is " . $color->getColorValue(\Imagick::COLOR_YELLOW) . "<br/>";
$output .=  "Black value is " . $color->getColorValue(\Imagick::COLOR_BLACK) . "<br/>";