Kiara wrote:- Code: Select all
<?php
$text='text';
$imgname='test.png';
$im = @imagecreatefrompng($imgname);
$color = imagecolorallocate($im, 255, 255, 255);
imagestring($im, 8, 5, 5, $text, $color);
imagepng($im);
imagedestroy($im);
?>
According to what one of the examples said, "imagecolorallocate($im,
255, 255, 255)" is supposed to make the background white, but it doesn't.
It's creating a colour of white (it's the same as #FFFFFF in HTML, a brightness of 255 in each of the red, green and blue channels combines to make white. 0,0,0 is black) and storing it in the variable $color. Later on, it uses that colour in the call to imagestring: It's using it as the text colour. When you say that the background ends up black, do you mean the background of the whole picture is black? Can you still see your pet image? Or do you mean the background of the text is black? A picture here would really help diagnose the problem

. You might try calling:
imagesavealpha($im, true);
Before your call to imagepng(). You're also missing this call:
header("Content-Type: image/png");
Before the call to imagepng. This tells the browser what kind of picture you are sending it. Some browsers can guess that it is a PNG image, but some can't, so you need this line to be compatible.
Have you checked out the documentation for imagestring? It explains what each parameter does:
http://nz.php.net/manual/en/function.imagestring.php