Transparency in GD2 not working..

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
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Transparency in GD2 not working..

Post by daedalus__ »

Code: Select all

function CreateHeader($text)
{
   $image		= imagecreatetruecolor(200, 21) or die("Could not create image.");
   $text_color	= imagecolorallocate($image, 60, 21, 0);
   $bg_color	= imagecolorallocate($image, 0, 0, 255);
   $background	= imagefilledrectangle($image, 0, 0, 200, 21, $bg_color);
	
   imagecolortransparent($image, $bg_color);
   imagettftext($image, 18, 0, 5, 18, $text_color, 'goudosb.ttf', $text);
   imagegif($image);
   imagedestroy($image);
}

header('Content-type: image/gif');
CreateHeader($_GET['text']);
Is there any reason why the following code should not work?

Try it out, the blue won't be transparent.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Transparent images can be a pain in the bum .. I always use imagecreatetruecolortransparent() .. http://www.phpgd.com/scripts.php?script=27
Post Reply