Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Transparency lost when using imagecopy in PHP

    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:

    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!!!
    Last edited by nathanelmori; 10-18-2009 at 12:37 AM. Reason: Problems with PHP tags

  • #2
    Regular Coder
    Join Date
    Nov 2007
    Location
    Leeds, UK
    Posts
    514
    Thanks
    24
    Thanked 19 Times in 19 Posts
    Quote Originally Posted by nathanelmori View Post
    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:

    Code:
    <html>
    
    <body bgcolor="red">
    
    PHP Code:
    <?php $im imagecreatefrompng("thepic.png"); imagealphablending($imtrue); imagesavealpha($imtrue); $test imagecreatetruecolor(imagesx($im), imagesy($im)); imagealphablending($testtrue); imagesavealpha($testtrue); imagecopy($test$im0000imagesx($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 think this might be a class limitation,

    check the php.net/gd stuff for it sorry i cant be more help i don't do GD library
    Working towards a Internet where we don't have website just browser applications Kill the Hyper-link and say hello to 3D Games in the browser :)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •