note 100307 added to function.imagecolorsforindex

From: Date: Thu, 07 Oct 2010 05:52:04 +0000
Subject: note 100307 added to function.imagecolorsforindex
Groups: php.notes 
Request: Send a blank email to php-notes+get-173047@lists.php.net to get a copy of this message
# 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 ---- Server IP: 89.31.146.176 Probable Submitter: 83.156.150.152 ---- Manual Page -- http://www.php.net/manual/en/function.imagecolorsforindex.php Edit -- https://master.php.net/note/edit/100307 Del: integrated -- https://master.php.net/note/delete/100307/integrated Del: useless -- https://master.php.net/note/delete/100307/useless Del: bad code -- https://master.php.net/note/delete/100307/bad+code Del: spam -- https://master.php.net/note/delete/100307/spam Del: non-english -- https://master.php.net/note/delete/100307/non-english Del: in docs -- https://master.php.net/note/delete/100307/in+docs Del: other reasons-- https://master.php.net/note/delete/100307 Reject -- https://master.php.net/note/reject/100307 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#173047) next »