note 101265 added to function.imagecolorallocate

From: Date: Mon, 06 Dec 2010 11:23:35 +0000
Subject: note 101265 added to function.imagecolorallocate
Groups: php.notes 
Request: Send a blank email to php-notes+get-174645@lists.php.net to get a copy of this message
Noticed a bug and can not find the solution yet. Here are two pieces of code. First I try to allocate an colour to the image and save the image <?php $im = @imagecreatetruecolor(200, 200) or die('Cannot Initialize new GD image stream'); $color = imagecolorallocate($im, 143, 198, 269); { for ($j=0; $j<200; $j++) { imagesetpixel ($im, $i, $j, $color); } } $filename = 'test.png'; imagepng($im, $filename); ?> In second piece I read the saved image and print the allocated color. <?php $filename = 'test.png'; $im = imagecreatefrompng($filename); $rgb = imagecolorat($im, 1, 1); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; echo "allocated color: r =".$r."g =".$g."b =".$b; ?> It prints : allocated color: r =143 g =199 b =13 Hence the allocated color is completely different from the one which I wanted. Any suggestion to deal with this problem. ---- Server IP: 69.147.83.197 Probable Submitter: 128.39.82.231 ---- Manual Page -- http://www.php.net/manual/en/function.imagecolorallocate.php Edit -- https://master.php.net/note/edit/101265 Del: integrated -- https://master.php.net/note/delete/101265/integrated Del: useless -- https://master.php.net/note/delete/101265/useless Del: bad code -- https://master.php.net/note/delete/101265/bad+code Del: spam -- https://master.php.net/note/delete/101265/spam Del: non-english -- https://master.php.net/note/delete/101265/non-english Del: in docs -- https://master.php.net/note/delete/101265/in+docs Del: other reasons-- https://master.php.net/note/delete/101265 Reject -- https://master.php.net/note/reject/101265 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#174645) next »