我正在尝试合并这些图片:
https://imgur.com/aURQax9 - 基地
https://imgur.com/a/cpiSc - 标记
结果应如下所示: https://imgur.com/a/ri3zw
我得到的图片正在删除所有黑色,但我不确定如何做到这一点。
$numberOfImages = 2;
$x = 600;
$y = 600;
$background = imagecreatetruecolor($x, $y);
$black = imagecolorallocate($background, 0, 0, 0);
imagecolortransparent($background, $black);
$firstUrl = 'Images/Horses/First horses/Red Breeds/Paint/Adult/Overo/1/BayOvero1AD.png';
$secondUrl = 'Images/Horses/First horses/Red Breeds/Paint/Markings/PaintBlazeAD.png';
$outputImage = $background;
$first = imagecreatefrompng($firstUrl);
$second = imagecreatefrompng($secondUrl);
imagecopymerge($outputImage,$first,0,0,0,0, $x, $y,100);
imagecopymerge($outputImage,$second,0,$y,0,0, $x, $y,100);
imagepng($outputImage, './Images/BayOvero1AD.PaintBlazeAD.png');
imagedestroy($outputImage);
如何更新此颜色,以便不删除颜色,并且它与上面完成的图像非常相似地合并?
答案 0 :(得分:1)
我刚刚为你写了这个。发布的图片之一是jpg而不是PNG,但这可能与imgur有关,因此我不得不调整它并删除一些白色。这就是为什么我的结果在测试时看起来不太正确的原因。但是原始文件应该没问题:
正如您所看到的,它在第一张图片上方添加了第二张图片,并将其保存在正确的位置。
我用的代码是:
<?php
$x = 600;
$y = 600;
$firstUrl = 'Images/Horses/First horses/Red Breeds/Paint/Adult/Overo/1/BayOvero1AD.png';
$secondUrl = 'Images/Horses/First horses/Red Breeds/Paint/Markings/PaintBlazeAD.png';
$Image1 = imagecreatefrompng($firstUrl);
$Image2 = imagecreatefrompng($secondUrl);
imagealphablending($Image1, true);
imagesavealpha($Image1, true);
imagecopy($Image1, $Image2, 0, 0, 0, 0, $x, $y);
imagepng($Image1, './Images/BayOvero1AD.PaintBlazeAD.png');
?>
&#13;