Page 1 of 1

[SOLVED] Image background of wrong colour

Posted: Tue Jun 29, 2004 6:38 pm
by evilmonkey
Hello. I am using imagecolorallocate() to set a background colour, but it doesn't seem to be working. In the PHP manual it says that the first call to imagecolorallocate() sets the background colour. I want my background to be white, instead, it's coming out as black. What am I doing wrong?

Code: Select all

<?php
$newimage = imagecreatetruecolor(200, 200);
$background = imagecolorallocate($newimage, 255, 255, 255); //should this set the background to white?
$black = imagecolorallocate($newimage, 255, 255, 255);
imagestring($newimage, 2, 3, 10, "some text in balck", $black);

header("Content-type: image/png");
imagepng($newimage);
imagedestroy($newimage);
?>

Posted: Tue Jun 29, 2004 10:13 pm
by HappyTchoum
mmm

Code: Select all

<?php 
$newimage = imagecreatetruecolor(200, 200); 
$background = imagecolorallocate($newimage, 255, 255, 255); //should this set the background to white? 
$black = imagecolorallocate($newimage, 255, 255, 255); 
imagestring($newimage, 2, 3, 10, "some text in balck", $black); 

header("Content-type: image/png"); 
imagepng($newimage); 
imagedestroy($newimage); 
?>

... Your background, you've put it in black with the 255's. It should be 0s instead.

Code: Select all

<?php 
$newimage = imagecreatetruecolor(200, 200); 
$background = imagecolorallocate($newimage, 0, 0, 0); //should this set the background to white? 
$black = imagecolorallocate($newimage, 255, 255, 255); 
imagestring($newimage, 2, 3, 10, "some text in balck", $black); 

header("Content-type: image/png"); 
imagepng($newimage); 
imagedestroy($newimage); 
?>
Let me tell you that this subject is quite [mod]!@#$ up... Prepare yourself. I still didn't found information how to put an image in the background without [mod]!@#$ all the other colors...

If you have an idea... contact me at happytchoum@hotmail.com. It would be very appreciated =O)

HappyTchoum

feyd | watch the language, Happy

Posted: Wed Jun 30, 2004 3:25 pm
by evilmonkey
No, unfortunatly that still keeps the background as balck. I feel like I've tried everything...Here's the modded code:

Code: Select all

$newimage = imagecreatetruecolor(200, 200);
$background = imagecolorallocate($newimage, 0, 0, 0); //this line is getting annoying :X
$black = imagecolorallocate($newimage, 255, 255, 255);
imagestring($newimage, 2, 3, 10, "text in black", $black);

header("Content-type: image/png");
imagepng($newimage);
imagedestroy($newimage);
I still need help :(

Posted: Wed Jun 30, 2004 6:36 pm
by redmonkey
It's the lesser documented changes, try this.....

Code: Select all

<?php
$newimage = imagecreatetruecolor(200, 200);
$background = imagecolorallocate($newimage, 255, 255, 255);
$fill = imagefill($newimage, 0, 0, $background);
$black = imagecolorallocate($newimage, 0, 0, 0);
imagestring($newimage, 2, 3, 10, "some text in balck", $black);

header("Content-type: image/png");
imagepng($newimage);
imagedestroy($newimage);
?>

Posted: Wed Jun 30, 2004 8:38 pm
by evilmonkey
Yup, that seems to have done it. Thanks very much. Also, can you please tell me how to include another .png image in my blank image? (overlay another image).

Thanks for the help!

Posted: Wed Jun 30, 2004 8:53 pm
by redmonkey
I would recommend you read through this GD tutorial/presentation, it gives examples and sample php code for many common tasks.

Posted: Wed Jun 30, 2004 8:56 pm
by evilmonkey
I got that going with imagecopy(). Thanks for the help everyone. :D