note 101265 rejected from function.imagecolorallocate by danbrown
| From: | danbrown@php.net | Date: | Mon, 06 Dec 2010 17:57:19 +0000 |
| Subject: | note 101265 rejected from function.imagecolorallocate by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-174661@lists.php.net to get a copy of this message | ||
Note Submitter: vineetg1 at hotmail dot com
----
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.