Forum Moderators: coopster
I have also tried dynamically generating the background but this will only go to fully transparent or fully opaque for some reason, despite changing the alpha setting.
The page and code is below, it's probably something stupid but I've tried so many combinations of settings that I've almost given up, so some help would be much appreciated :]
<snipped url>
PHP Code:
<?php
/* Attempt to overlay transparent and semi-transparent images */
$width = 120;
$height = 120;
$bottom_image = imagecreatefrompng("bottom_image.png");
$top_image = imagecreatefrompng("top_image.png");
imagesavealpha($top_image, true);
imagealphablending($top_image, false);
imagecopyresampled($bottom_image, $top_image, 0, 0, 0, 0, $width, $height, $width, $height);
imagepng($bottom_image, "new_image.png");
?>
Image generated at <a href="new_image.png">new_image.png</a>, see on a coloured bg <a href="test.html">here</a>
Many thanks,
Michael
[edited by: coopster at 3:06 pm (utc) on April 2, 2008]
[edit reason] no urls please TOS [webmasterworld.com] [/edit]
Instead of using imagecopyresampled, use imagecopy or imagecopymerge (with a $pct of 100).
Also, it's often tricky to manage the correct settings for imagesavealpha and imagealphablending. You probably need to set those both to be true on both the $bottom_image and $top_image handlers.
However, I have a lot of experience with dynamic image generation and I still sometimes have to play around with different combinations of true/false for those two settings before I get it right... Which is why GD often stands for something else when I am debugging similar problems. ;)
For now I've just used command line imagemagick with exec("convert bottom_image.png top_image.png -composite new_image.png"); I've spent far too many hours trying to find the combination of settings with GD, and for this task IM is much simpler :]
Thanks for the help though :]
Mike
[edited by: MJMason at 4:56 pm (utc) on April 2, 2008]