imagecopy doesn't work all the time

帅比萌擦擦* 提交于 2019-12-13 14:53:52

问题


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?


回答1:


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 http://imgur.com/kMqQbrr



来源:https://stackoverflow.com/questions/19720119/imagecopy-doesnt-work-all-the-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!