The GD-Lib is a very powerfull extension for PHP.
but in one case, it really fails.
Imagine, you want to merge an image with
৺alpha channels with another one.
No magic: u can use the
৺imagecopy() function. It will look like this:

imagecopy with an alpha channel watermark
Imagine, you want to merge an image without
৺alpha channels with another one,
AND add opacity.
No magic: u can use the imagecopymerge() function. (The
৺banner has white background)

imagecopymerge using alpha of 50
But now, imagine, you want to merge an image with
৺alpha channels with another one,
AND add opacity.
In this case, the GD-Lib fails:

imagecopymerge using alpha of 50 AND and watermark with alpha channels
Background:
Each pixel on an image is defined by 4 values: red, green, blue and
৺alpha.
If you use the
৺imagecopy function, the
৺alpha value will be preserved, which means:
what IS transparent will be transparent after merging.
If you use the imagecopymerge function you can set the new
৺alpha channel, BUT:
If you set up an
৺alpha channel of 100 (nearly transparent) EACH pixel will get this
৺alpha value.
This means, that if there are pixel with a value of 127 (totally transparent), they will be visible after merging - like in the third example above.
Solution:
i wrote an function called "imagecopymergealpha" which is able to solve this problem:

imagecopymergealpha
As u can see, transparent pixel are "staying" transparent, and opaque pixels are getting "more" transparent.
And this is, where the magic happens:
function imagecopymergealpha(&$dest_img, &$src_img, $dest_x, $dest_y, $src_x, $src_y, $src_width, $src_height, $alpha){
for ($x=0; $x < $src_width; $x++){
for ($y=0; $y < $src_height; $y++){
$new_alpha = $color["alpha"];
$new_alpha += $alpha;
if ($new_alpha > 127) $new_alpha = 127;
}
}
imagecopy($dest_img,$new_src,$dest_x,$dest_y,$src_x,$src_y,$src_width,$src_height); }
the last parameter - which is the "total"
৺alpha channel can get values from 0 - 127, where 0 means opaque and 127 totally invisible
Update 2009-11-09: Added imagedestroy command to free memory.