getting black background w/ imagepng

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
fairyprincess18
Forum Newbie
Posts: 21
Joined: Sun Dec 07, 2008 8:54 pm

getting black background w/ imagepng

Post by fairyprincess18 »

does anyone know why i get a black background when generating png images in the following code:

Code: Select all

 
//create image from existing png file
$im = imagecreatefrompng("overlay.png");
 
//transparent background and black text
//$bg = imagecolorallocate($im, 0, 0, 0);
//$bg = imagecolortransparent($im,$bg);
$textcolor = imagecolorallocate($im, 0, 0 , 0);
 
$divNum = 0;
 
$divNum = $bandwidth / 1000;
$gigNum = $divNum . "Gb";
 
//convert strings into images
imagestring($im, 5, 32, 20, $gigNum, $textcolor);
 
//directory in which to save generated images
$savePath = 'images/' . $gigNum . '.png';
 
//output images to files
header('Content-type: image/png');
imagepng($im, $savePath);
imagedestroy($im);
 
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: getting black background w/ imagepng

Post by onion2k »

Because imagesavealpha() is set to false.
fairyprincess18
Forum Newbie
Posts: 21
Joined: Sun Dec 07, 2008 8:54 pm

Re: getting black background w/ imagepng

Post by fairyprincess18 »

thanks, that did it
Post Reply