phpgd

imagecopy doesn't work all the time


I'm having an issue with imagecopy certain images on the $url variable will not appear even though there both PNG on the working and not working examples. The $local variable loads transparent images from the server and $url variable loads from a remote server. I have inculded a test transparent image for $local.

Working:

<?php
header("Content-type: image/png");
$url = imagecreatefrompng("url_removed.png");
$local = imagecreatefrompng("http://url_removed.png");
imagecopy($url, $local, 0, 0, 0, 0, 100, 100);
imagepng($url);
imagedestroy($url);
imagedestroy($local);
?>

Not working:

<?php
header("Content-type: image/png");
$url = imagecreatefrompng("url_removed.png");
$local = imagecreatefrompng("http://url_removed.png");
imagecopy($url, $local, 0, 0, 0, 0, 100, 100);
imagepng($url);
imagedestroy($url);
imagedestroy($local);
?>

I have even tried imagecreatestring with file_get_contents and that works also but certain PNG images it doesn't work just like with imagecreatefrompng

After all that said in done, I think it has something to do with imagecopy.... what can I do to fix this or is there another simple way of doing this?


Solution

  • i'd test with both codes, and it works

    <?php
    header("Content-type: image/png");
    $url = imagecreatefrompng("http://i.imgur.com/F7Jpk9y.png");
    $local = imagecreatefrompng("http://i.imgur.com/0A81XrP.png");
    // use imagecopymerge instead and set the copied image opacity to 50
    imagecopymerge($url, $local, 0, 0, 0, 0, 64, 64,50); 
    imagepng($url);
    imagedestroy($url);
    imagedestroy($local);
    ?>
    

    output https://i.sstatic.net/iqPYe.jpg