List Info

Thread: Error in Converting GIF Image to Balck & White




Error in Converting GIF Image to Balck & White
user name
2006-07-27 07:44:08
I have a doubt in php.I wrote a php program to convert
colour Images to
balck & white.It is working fine with JPEG files and PNG
files.When it
comes to GIF files I am not getting the colour Image.I think
I found
the reason of getting error.But I am not able to solve it
I am pasting the code which I wrote

The reason I think  is when I am extracting the RGB value
from the
image,R and G will be zero everytime.But I am getting the
value of B.
As a Result I am getting a Black Box instead of Black and
white Image


$file    = 'logo2.gif';
header('Content-type: image/gif');
 $imgtype = "gif";
list($width, $height) = getimagesize($file);
$source = imagecreatefromgif($file);
$bwimage= imagecreate($width, $height);

for ($c=0;$c<256;$c++)
{
$palette[$c] = imagecolorallocate($bwimage,$c,$c,$c);
}

function yiq($r,$g,$b)
{
 return (($r*0.299)+($g*0.587)+($b*0.114));

}
for ($y=0;$y<$height;$y++)
{
for ($x=0;$x<$width;$x++)
{
$rgb = imagecolorat($source,$x,$y);
$r = ($rgb >> 16) & 0xFF;//error is here I am
getting a value of zero
for $r and $g
$g = ($rgb >> 8) & 0xFF;//error getting the value
zero everytime
$b = $rgb & 0xFF;//Here I am getting value

$gs = yiq($r,$g,$b);
imagesetpixel($bwimage,$x,$y,$palette[$gs]);
}
} 

imagegif($bwimage);


--~--~---------~--~----~------------~-------~--~----~
This group is managed and maintained by the development
staff at 360 PSG. An enterprise application development
company utilizing open-source technologies for todays
small-to-medium size businesses.

For information or project assistance please visit :
http://www.360psg.com

You received this message because you are subscribed to the
Google Groups "Professional PHP Developers"
group.
To post to this group, send email to Professional-PHPgooglegroups.com
To unsubscribe from this group, send email to
Professional-PHP-unsubscribegooglegroups.com
For more options, visit this group at http:
//groups.google.com/group/Professional-PHP
-~----------~----~----~----~------~----~------~--~---

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )