473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Error in Converting GIF Image to Black & White

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);

Jul 31 '06 #1
1 2338
<re************@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>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

In the manual at php.net it says:
Note: GIF support was removed from the GD library in Version 1.6, and added
back in Version 2.0.28. This function is not available between these
versions.

Check your GD version to see if it supports gif or not.

(I remember a time when gif was not supported. It's nice to see they've
added it in the package again.)

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net || Gedoon-S @ IRCnet || rot13(xv***@bhgbyrzcv.arg)
Jul 31 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: MrNobody | last post by:
Let's say I have an image which is monochrome with areas of white, black and shades of gray. Now I want to turn all the white parts into some RGB color but it also needs to be darkened by the gray...
25
by: Blasting Cap | last post by:
I keep getting errors that pop up when I am trying to convert an application from dotnet framework 1.1 to framework 2.0. The old project was saved in sourcesafe from Visual Studio 2003, and I have...
1
by: dishal | last post by:
Can anyone help me please? How do I convert these codes to launch from a JFrame instead of a Java Applet? A simple program where the user can sketch curves and shapes in a variety of...
3
by: Muddasir | last post by:
hi all i need to upload an image and if that image is coloured i need to convert it to black and white image ... till now i only uploaded images ... simple.. have no idea how to do this...
1
by: finizaini | last post by:
I'm receiving an "Object Expected" Error (Line:309, Char:0). I'm confused as to what is happening.Also, I can't run this code using other browser such as Fire Fox. Thispage only can view using IE....
1
by: sravani1 | last post by:
This code runs like when i submit the form it takes the image and displayed and top of the image a map will displayed. But actually i want that when i give the image it checks the location in the map...
4
by: Ty | last post by:
Hello all, I am creating a web site with Visual Stuido 2008. I am trying to use a java script file to create a busybox for login from this page http://blogs.crsw.com/mark/articles/642.aspx. I...
3
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine...
2
by: studentofknowledge | last post by:
For some unknown reason ie is placing images I have in a div in a weird way. One image is overlapping another but this problem is not occuring in mozilla. I have looked at my code over and over again...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.