Transparency gone, only black background

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

Moderators: onion2k, General Moderators

Transparency gone, only black background

Postby stephankn » Wed Aug 31, 2011 6:00 pm


I hope to get some advice here.
I'm currently working on a little script that dynamically creates images that will serve as an overlay to other images by using transparent areas. The browser will layer these using OpenLayers.

Up to last week my prototype worked fine. The images had a completely transparent background with different colored blocks being slightly transparent.

Now the transparency is gone, I just get a black background where in the past the transparency had been. I was actively working on the script, but don't remember having changed anything substantial on the painting itself.

What I did: I updated apache on the server to fix the DOS problem regarding range requests. I checked the logs, that update did only affect apache. Config files look unchanged. No php or GD was changed if I see it right.

System is a debian squeeze. apache2 is 2.2.16-6+squeeze2, php5 is 5.3.3-7+squeeze3, php5-gd is 5.3.3-7+squeeze3

So is this an issue with the software or with my script? I have created the following code to reproduce the problem:
When invoked from the command line the image is like expected. Problem occurs when called using apache and mod_php.

Syntax: [ Download ] [ Hide ]

$img = imagecreatetruecolor(256, 256);
imagealphablending($img, false);
imagesavealpha($img, true); // single color transparency works with savealpha = false
$transparent = imagecolorallocatealpha( $img, 0x00, 0x00, 0x00, 127 );
//imagecolortransparent($img, $transparent); // causing single-color transparency. I also want colored parts being transparent so this is no option
imagefill($img, 0, 0, $transparent);
$color_yellow = imagecolorallocatealpha($img, 255, 214, 51, 40);
imagefilledrectangle($img, 0, 0, 15, 15, $color_yellow);
header("Content-type: image/png");              

Thank you already for your time,

Forum Newbie
Posts: 1
Joined: Wed Aug 31, 2011 5:36 pm

Return to

Who is online

Users browsing this forum: Google [Bot] and 2 guests