mjmason
04-02-2008, 08:43 AM
I'm using GD to overlay a selection of images with transparent backgrounds, and I can get this working fine, however when I then try to overlay the generated image on top of a semi transparent white image, the background turns white instead of remaining semi transparent.
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 :]
http://www.randomcows.com/overlay.php
<?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
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 :]
http://www.randomcows.com/overlay.php
<?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