473,407 Members | 2,315 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,407 software developers and data experts.

GD intermittent color problem

118 100+
Hey folks, yet again.

[php]


if ($back == "m") //$back is a value pulled from a db; that works perfectly.
{
$wid = $rowing['width'];
$hei = $rowing['height'];
createthumb("660x240background2.gif", "./user/" . $user . "_back.gif", $wid, $hei);

$image = imagecreatefromgif("./user/" . $user . "_back.gif");
$blue = ImageColorAllocate($image, 200, 200, 255); // prepare some blueness
$black = ImageColorAllocate($image, 0, 0, 0); // ... and whiteness
$im = ImageCreate(300, 35);
$black_a = imagecolorallocate($im, 0, 0, 0);
$white_a = imagecolortransparent($im, $black_a);
$white = ImageColorAllocate($im, 255, 255, 255);
ImageFill($im, 0, 0, $white_a);
Imagettftext($im, 15, 0, 10, 30, $white, $font, $user . "'s Shoutbox");

$cur_line_y = 65; // This stores how far down the image the current line will print

$postperpage = 11;
}
elseif ($back == "u")
{
$wid = $rowing['width'];
$hei = $rowing['height'];



// createthumb("./user/".$user."_img.gif", "./user/" . $user . "_backim.gif", $wid, $hei);

imagecreatefromgif("./user/" . $user . "_img.gif");



$images = imagecreate($wid, $hei);

$imge = imagecreatefromgif("./user/" . $user . "_backim.gif");

imagecopymerge($images, $imge, 0, 0, 0, 0, $wid, $hei, 20);

imagegif($images, "./user/" . $user . "_back_trans.gif");

$image = imagecreatefromgif("./user/" . $user . "_back_trans.gif");

$im = ImageCreate(300, 35);
$black_a = imagecolorallocate($im, 0, 0, 0);
$white_a = imagecolortransparent($im, $black_a);
$white = ImageColorAllocate($im, 255, 255, 255);
ImageFill($im, 0, 0, $white_a);
Imagettftext($im, 15, 0, 10, 30, $white, $font, $user . "'s Shoutbox");

$cur_line_y = 74; // This stores how far down the image the current line will print
$postperpage = 10;
}

$sql = ""; // no need for actuall SQL statement - it works.

$result = mysql_query($sql) or die("error in sqllls: " . mysql_error());


$cur_line_x = 24; // This stores how far across the image the current line will print
$pagecharwidth = 75; // this is the maximum length of the line before it wraps;
$lineheight = 18; // This is how much to move down to print the next line
$pagelinelimit = 1; // How many of each comment appears per page.


//ImageString($image, 3, 15, $cur_line_y, trim(stripslashes($wordwrapped[0])), $black);

$numberOfLines = $pagelinelimit;

for ($i = 0; $i < $numberOfLines; $i++)
{
while ($row = mysql_fetch_array($result))
{

$name = "[" . htmlspecialchars_decode($row['username']) . "] "; //it works - returns username
$font = $row['font']; //it works - renders the colour
$color = $row['color']; //it works - changes the font
$line = htmlspecialchars_decode($row['comment']); //it works, posts the shout

if ($name == "[] ")
{
$name = "";

$line = $name . $line;
}
else
{
$line = $name . $line;

}

//code for emoticons.

//add shouts to image!
if ($back == "m" )
{
if ($color == "white" || $color == "yellow" || $color == "green" || $color ==
"orange" || $color == "aqua")
{
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont
($font), trim($line));


}
elseif ($color != "white" || $color != "yellow" || $color != "green" || $color !=
"orange" || $color != "aqua")
{
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $white, getfont($font),
trim($line));


}
elseif ($font == "fixedsys" || $font == "Courbd" || $font == "arial" || $font ==
"timesnr" || $font == "calibri" || $font == "comicsans" || $font == "palab")
{
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont
($font), trim($line));


}
else
{
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $white, "courbd.ttf", trim
($line));


}

}
elseif ($back == "w" )
{

$blac = imagecolorallocate($image, 0, 0, 0);

if ($color == "black" || $color == "purple" || $color == "blue" || $color ==
"emerald" || $color == "red")
{
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont
($font), trim($line));


}
elseif ($color != "black" || $color != "purple" || $color != "blue" || $color !=
"emerald" || $color != "red")
{
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $blac, getfont($font),
trim($line));


}
elseif ($font == "fixedsys" || $font == "Courbd" || $font == "arial" || $font ==
"timesnr" || $font == "calibri" || $font == "comicsans" || $font == "palab")
{
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont
($font), trim($line));


}
else
{
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $white, "courbd.ttf", trim
($line));


}

}


[/php]

Depending on the values of $back, the background of the image changes and the font colours also change. This code works so far.

Problem code

[php]
elseif($back == "u")
{
if ($color == "white" || $color == "yellow" || $color == "green" || $color ==
"orange" || $color == "aqua")
{
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont
($font), trim($line));


}elseif ($color != "black" || $color != "purple" || $color != "blue" || $color !=
"emerald" || $color != "red")
{
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $white, getfont($font),
trim($line));


}
elseif ($font == "fixedsys" || $font == "Courbd" || $font == "arial" || $font ==
"timesnr" || $font == "calibri" || $font == "comicsans" || $font == "palab")
{
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, getColor($color), getfont
($font), trim($line));


}
else
{
Imagettftext($image, 10, 0, $cur_line_x, $cur_line_y, $white, "courbd.ttf", trim
($line) . " ");


}
}

$cur_line_y += $lineheight;


}
}
[/php]

The problem is that when $back == "u", for the first two comments the colours are normal then after that the older comments turn black; the newest comment is in colour but it also changes the colour of the $im that says "User's Shoutbox", which is created as a seperate image.

I can't, for the life of me, see the problem.. can you?

An example: $back == "u" because it's an uploaded background. The oldest comment was white, then I added the Yellow comment, the white one turned black.

http://www.helraizer.co.uk/mychatbox/user/lucifer.gif


Hope that makes sense; if you need more code, just ask. =)
Sam
Jun 6 '08 #1
3 2068
helraizer1
118 100+
*bump*

Any one got any ideas?

The process of the background image is that when they upload it as either jpg, gif or png; it is converted to and saved a gif file.

So I uploaded this image

http://www.helraizer.co.uk/mychatbox...ucifer_img.gif

which then is pulled into the code where $back == "u" the first time. It is the saved to the user's specified dimensions. So creates this (700x290, in this case).

http://www.helraizer.co.uk/mychatbox...fer_backim.gif

It is the merged onto a gd made image at the same dimensions, this time at 20% transparency. Which gives this:

http://www.helraizer.co.uk/mychatbox...back_trans.gif

That final, darkened image is what the shouts are written onto. Is there any way this process could be affecting the colours? I can't imagine it can because this process happens seperately each time, before the shouts are written on.

Sam


EDIT: Fixed it!

Used imagecreatetruecolor($wid, $hei); instead of imagecreate(). It works perfectly now.
Jun 6 '08 #2
helraizer1
118 100+
The imagecreatetruecolour only solved it for a little while, allowing one more comment of colour than before, now the comments do the same thing.

Any ideas why when a new comment is posted, the imagecolorallocate fails and the comments turn black?

supposed to be like:

http://www.helraizer.co.uk/mychatbox/user/helraizer.gif - plain background, colours work!

but ends up like:

http://www.helraizer.co.uk/mychatbox/user/lucifer.gif - detailed background, colours only work part of the time.

Please reply if you have any theories.

Sam
Jun 7 '08 #3
helraizer1
118 100+
Fixed it again. xD

Used the same technique but this time I've made it as png. That way it doesn't run out of colours on the pallete and gives the same result.

Sam
Jun 7 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Anthony | last post by:
I have a php app that is in the final stages of testing and has been tested by over 30 separate users. One of the testers is having an intermittent problem which seems to be caused by a session...
1
by: bloodhound | last post by:
Hi, Problem with global.asa not firing 100% of the time. This error crops up several times throughout the day but if you wait a while and reload the page (could be 5 mins or an hour) it will...
2
by: deevoy | last post by:
Hi- I'm developing a asp.net web application and everything has proven fine on the dev and acceptance environment. We've moved the code up to our windows server 2003 prod environment and get the...
2
by: gary | last post by:
I am using VS.NET 2003 on XP I intermittently get Access is denied '' at the line <add assembly="*"/> in machine.config I have disabled indexing service and I am not running any form of...
8
by: trinitypete | last post by:
Hi all I have a strange problem with IIS windows pass through authentication. Heres the setup IIS running with Windows Authentication for our intranet site. ACL has been set to everyone for all...
2
by: Mike Krajewski | last post by:
We are having an intermittent problem using an ExecuteScalar command on a asp.NET page accessing SQL Server. 2 characters of the sql statement get intermittently altered. The code looks as...
3
by: Lee Chapman | last post by:
Hi, I have a problem where my ASP.NET application occasionally generates a MissingFieldException exception. This unexpectedly happened on my development box, and so I was able to extract some...
0
by: Shane C | last post by:
Intermittent Error: Server was unable to process request  Object reference not set to an instance of an object I have windows application that references a XML web service on our web server. ...
0
by: Joey Bersche | last post by:
I've been experiencing an intermittent crash where no python stacktrace is provided. It happens for a url downloading process that can last up to 12 hours and crawls about 50,000 urls. I'm...
15
by: jonnyboy | last post by:
Hello, I'm having an intermittent problem with the back-end of my database. On an intermittent basis, the back-end tables will become read-only. This only happens when the back-end is located...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.