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:
<?php
$im=new Imagick( 'image.png' );
$iterator=$im->getPixelIterator();
foreach ($iterator as $row=>$pixels) {
foreach ( $pixels as $column => $pixel ){
$un_color=$pixel->getColor(); //unnormalized color
$nor_color=$pixel->getColor(true); //normalized color
$pixel->setColor('rgba('.$un_color['r'].','.$un_color['g'].','.$un_color['b'].','.$nor_color['a'].')');
}
}
?>
If you use 'a' (alpha) value from the unnormalized color there will only be binary transparency.
ImagickPixel::getColor
(PECL imagick 2.0.0)
ImagickPixel::getColor — Retourne la couleur
Description
array ImagickPixel::getColor
([ bool
$normalized = false
] )Avertissement
Cette fonction n'est pas documentée et seule la liste des arguments est disponible.
Retourne la couleur décrite par l'objet ImagickPixel, sous la forme d'un tableau. Si la couleur contient un canal d'opacité, il sera fourni comme quatrième valeur de la liste.
Liste de paramètres
-
normalized -
Valeurs normalisées de la couleur
Valeurs de retour
Un tableau de valeurs de canaux, chacun normalisé si TRUE est fourni
comme argument. Lance une exception ImagickPixelException
si une erreur survient.
roman ¶
10 days ago
