Page 1 of 1

[SOLVED] Putting dynamic text on a static image

Posted: Sat Jun 26, 2004 2:14 pm
by evilmonkey
Hello.

I have a static image with a place on which dynamic text may be placed. I made code to dothis, but I have a problem with this. I want black text on a white background, but I get yellow on white instead, and it looks bad. Here's the code, please help me.

Code: Select all

$origpng= "testpic.png"; 

$imgsize = getimagesize($origpng);

$newwidth = round($imgsize['0']/1);

$newheight = round($imgsize['1']/1);

$imgwidth = $imgsize['0'];

$imgheight = $imgsize['1'];

$image = imagecreatefrompng($origpng);

$newimage = imagecreate($newwidth, $newheight);

//i imagine the problem is here
$bg = imagecolorallocate($image, 0,0,0);
$black = imagecolorallocate($image, 0, 0, 255); //I also tried 0,0,0 and 255, 255, 255 to no avail


imagecopyresized($newimage, $image, 0, 0, 0, 0, $newwidth, $newheight, $imgwidth, $imgheight);

imagedestroy($image);

imagestring($newimage, 2, 20, 20, "some text here", $black);

header("Content-type: image/png");

imagepng($newimage);

imagedestroy($newimage);

?>

Posted: Sun Jun 27, 2004 8:49 am
by scorphus
Try allocating color for $newimage instead of $image:

Code: Select all

//...
$bg = imagecolorallocate($newimage, 0,0,0);
$black = imagecolorallocate($newimage, 0, 0, 0);
//...
Scorphus.

Posted: Sun Jun 27, 2004 3:28 pm
by evilmonkey
Foolish me. Thank you, that worked. Best of luck. :)

~Jack.