note 100307 deleted from function.imagecolorsforindex by danbrown
| From: | danbrown@php.net | Date: | Thu, 07 Oct 2010 16:06:01 +0000 |
| Subject: | note 100307 deleted from function.imagecolorsforindex by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173055@lists.php.net to get a copy of this message | ||
Note Submitter: philippe dot perret at yahoo dot fr
----
# In response to matrebatre
"With eg GIF images, this will have strange results."
No strange results in fact. What we have to understand is that :
When the image resource has been created withâ¦
<?php
$img = imageCreateTrueColor($largeur, $hauteur);
?>
⦠then imageColorAt returns an : *** integer representing the RGB *** (for instance 2569875).
So, to retrieve the red-green-blue values, you have to use (your code) :
<?php
$rgba = imagecolorat($img, $x, $y);
$r = ($rgba >> 16) & 0xFF;
$g = ($rgba >> 8) & 0xFF;
$b = $rgba & 0xFF;
$a = ($rgba & 0x7F000000) >> 24;
?>
BUTâ¦
When the image resource has been created withâ¦
<?php
$img = imageCreateFromXXX($largeur, $hauteur);
// where "XXX" can be "gif", or "png" and so on
?>
⦠then imageColorAt returns an : *** the color index of the pixel in the palette *** (for
instance 1).
So, to retrieve the red-green-blue values, you must use :
<?php
$index = imageColorAt($img, $x, $y);
$data_couleur = imageColorsForIndex($img, $index);
extract($data_couleur, EXTR_PREFIX_ALL, "d");
//=> $d_red, $d_green, $d_blue, $d_alpha
?>
Hope it helps