473,796 Members | 2,729 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($f ile);
$source = imagecreatefrom gif($file);
$bwimage= imagecreate($wi dth, $height);
for ($c=0;$c<256;$c ++)
{
$palette[$c] = imagecoloralloc ate($bwimage,$c ,$c,$c);

}
function yiq($r,$g,$b)
{
return (($r*0.299)+($g *0.587)+($b*0.1 14));
}
for ($y=0;$y<$heigh t;$y++)
{
for ($x=0;$x<$width ;$x++)
{
$rgb = imagecolorat($s ource,$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($bwima ge);

Jul 31 '06 #1
1 2361
<re************ @gmail.comwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.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***@bhg byrzcv.arg)
Jul 31 '06 #2

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

Similar topics

4
5221
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 areas for the same color. Like say it's an image of a sphere, it is white in the part it is under the light but then as you get away from the light source it becomes darker and darker gray. Now I want to take this image and apply just one RGB...
25
4395
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 opened it in Visual Studio 2005. I've cleared up most errors, but have one that beats the heck out of me. I have a page: sales/Item.aspx that has several datagrids in it.
1
6644
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 colors on a variety of background colors. The user selects a drawing color form a pop-up menu at the top of the applet. If the user clicks "Set Background", the background color is set to the current drawing color and the drawing ...
3
6014
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 (converting) thing.... please help me out .. i just uploaded images so i guess it will be of no use for you people if i put my code here ...
1
1748
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. Is there something that I'm missing? The error is pointing to <textarea name="tairbillno" cols="25" rows="4" wrap="HARD" id="tairbillno" ONKEYDOWN="return checkMaxRow(this, 10)"></textarea> Here is my code below: <HTML> <HEAD>...
1
2038
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 and after displayed it.plz tell that how to start the logic. <?php // Connect to database $errmsg = "";if (! @mysql_connect("localhost","root","sreeni")) { $errmsg = "Cannot connect to database"; } @mysql_select_db("my_db1");...
4
3877
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 am using a master page senerio. The erro I'm getting is 'busyBox' is not a member of 'ASP.login2_aspx'
3
4437
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 when iam using a normal web page... but can't in content page.... Code in Master Page <%@ Master Language="C#" AutoEventWireup="true" CodeFile="submaster.master.cs" Inherits="submaster" %> <%@ Register Assembly="AjaxControlToolkit"...
2
4095
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 but cant seem to find out what the problem is. I think this could be fixed with a i.e hack??? please advise the problem of the overlapping image is occuring in imagerow2 div on line 56. please see my code below here is my html <!DOCTYPE...
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10465
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10242
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7558
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6800
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.