imagecopy并非一直有效 [英] imagecopy doesn't work all the time
问题描述
我遇到imagecopy
问题,即使在工作示例和不工作示例上都出现了PNG
,但$url
变量上的某些图像也不会出现. $local
变量从服务器加载透明图像,而$url
变量从远程服务器加载.我已经为$local
灌装了一张测试透明图像.
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
.
工作:
<?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);
?>
不起作用:
<?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);
?>
我什至尝试用file_get_contents
进行imagecreatestring
,并且也可以工作,但是某些PNG
图像却不能像imagecreatefrompng
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
说完之后,我认为这与imagecopy
有关系....我该怎么做才能解决此问题,或者还有另一种简单的方法可以做到这一点?
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?
推荐答案
我将同时测试这两种代码,并且有效
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);
?>
这篇关于imagecopy并非一直有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!