nathanelmori
10-17-2009, 11:34 PM
Hi
I am desperately trying to create an animated gif from two png files.
I found a great class that does this, and it works fine, except for the transparency, which is lost.
So I decided to narrow down the whole thing to try and locate the origin of the problem, and - lo and behold - the problem has nothing to do with the animation, but with the gd library.
In short, I can't even create an image from png and display it.
Here's a simple version of the code:
<html>
<body bgcolor="red">
<?php
$im = imagecreatefrompng("thepic.png");
imagealphablending($im, true);
imagesavealpha($im, true);
$test = imagecreatetruecolor(imagesx($im), imagesy($im));
imagealphablending($test, true);
imagesavealpha($test, true);
imagecopy($test, $im, 0, 0, 0, 0, imagesx($test), imagesy($test));
header('content-type: image/png');
imagepng($test, "test.png");
?>
<img src=test.png>
</body>
</html>
For some reason, the variable $test completely lost the original transparency (showing the default 'black' instead of the original transparent colors of the source), although I turned all the possible tags. However, $im still has the transparency and saving it into a file and showing it would work wonders. Alas, the reason I'm stuck in this conundrum is because I need to copy a part of $im into $test, and I can't complete that without losing the transparency.
HELP!! PLEASE!!!
I am desperately trying to create an animated gif from two png files.
I found a great class that does this, and it works fine, except for the transparency, which is lost.
So I decided to narrow down the whole thing to try and locate the origin of the problem, and - lo and behold - the problem has nothing to do with the animation, but with the gd library.
In short, I can't even create an image from png and display it.
Here's a simple version of the code:
<html>
<body bgcolor="red">
<?php
$im = imagecreatefrompng("thepic.png");
imagealphablending($im, true);
imagesavealpha($im, true);
$test = imagecreatetruecolor(imagesx($im), imagesy($im));
imagealphablending($test, true);
imagesavealpha($test, true);
imagecopy($test, $im, 0, 0, 0, 0, imagesx($test), imagesy($test));
header('content-type: image/png');
imagepng($test, "test.png");
?>
<img src=test.png>
</body>
</html>
For some reason, the variable $test completely lost the original transparency (showing the default 'black' instead of the original transparent colors of the source), although I turned all the possible tags. However, $im still has the transparency and saving it into a file and showing it would work wonders. Alas, the reason I'm stuck in this conundrum is because I need to copy a part of $im into $test, and I can't complete that without losing the transparency.
HELP!! PLEASE!!!