(PECL imagick 2, PECL imagick 3)

ImagickPixel::getColorReturns the color


public ImagickPixel::getColor ([ int $normalized = 0 ] ) : array

Returns the color described by the ImagickPixel object, as an array. If the color has an opacity channel set, this is provided as a fourth value in the list.

Elenco dei parametri


Normalize the color values. Possible values are 0, 1 or 2.

List of possible values for normalized
normalized Description
0 The RGB values are returned as ints in the range 0 to 255 (inclusive.) The alpha value is returned as int and is either 0 or 1.
1 The RGBA values are returned as floats in the range 0 to 1 (inclusive.)
2 The RGBA values are returned as ints in the range 0 to 255 (inclusive.)

Valori restituiti

An array of channel values. Throws ImagickPixelException on error.


Example #1 Basic Imagick::getColor() usage


//Create an ImagickPixel with the predefined color 'brown'
$color = new ImagickPixel('brown');

//Set the color to have an alpha of 25%
$color->setColorValue(Imagick::COLOR_ALPHA64 256.0);

$colorInfo $color->getColor();

"Standard values".PHP_EOL;

$colorInfo $color->getColor(1);

"Normalized values:".PHP_EOL;


Il precedente esempio visualizzerĂ :

Standard values
    [r] => 165
    [g] => 42
    [b] => 42
    [a] => 0
Normalized values:
    [r] => 0.64705882352941
    [g] => 0.16470588235294
    [b] => 0.16470588235294
    [a] => 0.25000381475547

add a note add a note

User Contributed Notes 1 note

7 years ago
In case you use default un-normalized getColor value the alpha value will always be either 0 or 1.

If you want to use real full-range 0-1 alpha channel on your 24bit transparent images use the alpha value from the normalized one, even if you use the rest of unnormalized data.

To copy a 24bit png with real alpha transparency, you would have to do this:

=new Imagick( 'image.png' );
foreach (
$iterator as $row=>$pixels) {
    foreach (
$pixels as $column => $pixel ){
$un_color=$pixel->getColor(); //unnormalized color
$nor_color=$pixel->getColor(true); //normalized color

If you use 'a' (alpha) value from the unnormalized color there will only be binary transparency.
To Top