BWWebDesigns
02-27-2008, 02:44 PM
Im using the following image code to generate an image on the fly
It usess several lines of text and i want text to be different colors dependant on certain things
However when i try and alocate text color to more than one of the text elements they all go a horrible light brown color and black alternating colors
brown
black
brown
black
etc
Code im using is
$pic = "donation-meter".$imgsrc.".gif";
$im = imagecreatefromgif($pic); /* Attempt to open */
//$bg = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
$goal = number_format ($goal, 2);
$string = "Goal : ".$cursym.$goal;
if($new_value2>=$goal) {
$redgreena = imagecolorallocate($im, 0, 255, 0);
} else {
$redgreena = imagecolorallocate($im, 255, 0, 0);
}
$string2 = "Donated : ".$cursym.$new_value2;
$red = imagecolorallocate($im, 255, 0, 0);
$string3 = "PP Fees : ".$cursym.$fees;
$left = $goal-($new_value-$fees);
$left = number_format ($left, 2);
if(eregi("-",$left)) {
$redgreenb = imagecolorallocate($im, 0, 255, 0);
} else {
$redgreenb = imagecolorallocate($im, 255, 0, 0);
}
$string4 = "Left : ".$cursym.$left;
$string5 = $res."% Of Our Goal";
$px = (imagesx($im) - 18 * strlen($string)) / 2;
imagestring($im, 2, 13, 35, $string, $black);
imagestring($im, 2, 13, 55, $string2, $redgreena);
imagestring($im, 2, 13, 75, $string3, $red);
imagestring($im, 2, 13, 95, $string4, $redgreenb);
imagestring($im, 2, $px, 115, $string5, $textcolor);
imagegif($im);
imagedestroy($im);
Depending on certain situations based on the value of a number to appear within a particular line of text the color of that text will be red or green
The rest of the text should be black
Can anyone offer advice on why it is not doing this
I have read many sites and my code seems to be right
It usess several lines of text and i want text to be different colors dependant on certain things
However when i try and alocate text color to more than one of the text elements they all go a horrible light brown color and black alternating colors
brown
black
brown
black
etc
Code im using is
$pic = "donation-meter".$imgsrc.".gif";
$im = imagecreatefromgif($pic); /* Attempt to open */
//$bg = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);
$goal = number_format ($goal, 2);
$string = "Goal : ".$cursym.$goal;
if($new_value2>=$goal) {
$redgreena = imagecolorallocate($im, 0, 255, 0);
} else {
$redgreena = imagecolorallocate($im, 255, 0, 0);
}
$string2 = "Donated : ".$cursym.$new_value2;
$red = imagecolorallocate($im, 255, 0, 0);
$string3 = "PP Fees : ".$cursym.$fees;
$left = $goal-($new_value-$fees);
$left = number_format ($left, 2);
if(eregi("-",$left)) {
$redgreenb = imagecolorallocate($im, 0, 255, 0);
} else {
$redgreenb = imagecolorallocate($im, 255, 0, 0);
}
$string4 = "Left : ".$cursym.$left;
$string5 = $res."% Of Our Goal";
$px = (imagesx($im) - 18 * strlen($string)) / 2;
imagestring($im, 2, 13, 35, $string, $black);
imagestring($im, 2, 13, 55, $string2, $redgreena);
imagestring($im, 2, 13, 75, $string3, $red);
imagestring($im, 2, 13, 95, $string4, $redgreenb);
imagestring($im, 2, $px, 115, $string5, $textcolor);
imagegif($im);
imagedestroy($im);
Depending on certain situations based on the value of a number to appear within a particular line of text the color of that text will be red or green
The rest of the text should be black
Can anyone offer advice on why it is not doing this
I have read many sites and my code seems to be right