Interesting problem notices in php imagecolorallocate. I am stuck and need valuable suggestions
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. Now How do I deal with this. Any suggestions please.
精彩评论