Hey guys,
Has anyone had experience using PHP and GD to:
1. Create transparent PNGs (I got this part working)
2. Add transparent PNGs on top of another one (this part works except for transparency - I get white instead)
Currently what I have is:
- Create transparent image canvas
- Add png image with transparency
This image resource comes out fine using imagepng(), but if I try to add another transparent PNG to this image resource they come out with the white background.
I've used every combination I could find in the comments on php.net, for most people it just seems to work.
Code below:
$image = imagecreatetruecolor($width, $height);
//turn on alpha transparency
imagealphablending($image, false);
imagesavealpha($image, true);
$base = imagecreatefrompng($base);
imagecopyresampled($image, $base, 0, 0, 0, 0, $width, $height, $width, $height);
return $image;
(creates the canvas, adds png)
If I do this with my other PNG and output it, it's transparent, but as soon as I merge them (imagecopy() or imagecopyresample()) I get the white background.
I've also tried to write text, however PHP/GD continue to complain that it can't find the .ttf files, however I reference them, and no matter where they are. I'm on Windows, and I tried putting the ttf in the same directory as php file, relative paths, absolute paths, etc..
Posts
You should also see if works with imagecopy or imagecopyresized. (the re-sampling might not be doing the right thing with the alpha channel.)
If I use that code, with my other image as $base, it works.
When I use imagecopy or imagecopyresampled, the source loses its transparency when merged into the destination
imagealphablending($image, true);
Where $image is the "bottom" image (the one you are merging the new image ON to)
However my font problem remains