我会在另一个图像中放置一个徽标图像,这两个图像是png,我尝试了imagecopy和imagecopymerge这两个函数但没什么可做的,我在磁盘上打开图像时看不到结果,但两个函数都返回真正。有人可以帮助我,这是我使用的代码:
$data = substr($_POST['imageData'], strpos($_POST['imageData'], ",") + 1);
$decodedData = base64_decode($data);
$img = "assets\\images\\simulation\\user\\img777.png";
$srcpath = "assets\\images\\logo.png";
fp = fopen($img , 'wb');
fwrite($fp, $decodedData);
fclose($fp);//work until this place
$dest =imagecreatefrompng($img);
$src =imagecreatefrompng($srcpath);
imagecopy ($dest,$src, 0, 0, 0, 0, imagesx($src),imagesy($src));
// or imagecopymerge ($dest,$src, 0, 0, 0, 0, imagesx($src),imagesy($src), $pct); with $pct =0 or 50
/*or i have also try : $cut = imagecreatetruecolor(imagesx($src),imagesy($src));
imagecopy($cut, $dest, 0, 0, 0, 0, imagesx($src),imagesy($src));
imagecopy($cut, $src, 0, 0, 0, 0, imagesx($src),imagesy($src));
imagecopymerge ($dest,$cut, 0, 0, 0, 0, imagesx($src),imagesy($src), $pct); with $pct =0 or 50*/
以下是image logo.png的示例:http://upload.wikimedia.org/wikipedia/commons/4/48/EBay_logo.png
这是另一个image.png:http://www.noelshack.com/2014-40-1412264764-img68634dxn777.png
结果与image.png ...
相同 你能帮助我吗,谢谢你。答案 0 :(得分:0)
我使用以下代码解决了这个问题:
imagealphablending($dest, true);
imagealphablending($src, true);
imagesavealpha($dest, true);
imagesavealpha($src, true);
imagecopy ($dest,$src, 5, imagesy($dest) - (imagesy($src)+5), 0, 0,imagesx($src),imagesy($src));
imagealphablending($dest, true);
imagesavealpha($dest, true);
imagepng($dest,$img);
imagedestroy($dest);
imagedestroy($src);
取代:
$dest =imagecreatefrompng($img);
$src =imagecreatefrompng($srcpath);
imagecopy ($dest,$src, 0, 0, 0, 0, imagesx($src),imagesy($src));