我想在php中使用gd在图像上添加一个颜色层。
我想用这种颜色覆盖它:#ABD0D2
我快速了解了它应该如何看待最后。请记住,图像应该仍然是透明的
到目前为止,我有这个代码:
$img = imagecreatefrompng('image.png');
imagesavealpha($img, true);
imagefill($img, 0, 0, imagecolorallocatealpha($img, 0, 0, 0, 127));
// make overlay with new color???
imagepng($img, 'new.png');
imagedestroy($img);
您可以创建一个填充目标颜色的新图像,然后将两者合并:
$img = imagecreatefrompng('image.png');
$w = imagesx($img);
$h = imagesy($img);
imagesavealpha($img, true);
$img2 = imagecreatetruecolor($w, $h);
imagefill($img2, 0, 0, imagecolorallocatealpha($img, 0xAB, 0xD0, 0xD2, 64));
imagecopy($img, $img2, 0, 0, 0, 0, $w, $h);
imagepng($img, 'new.png');
imagedestroy($img);
imagedestroy($img2);
结果:
我不清楚你想要如何保持透明度(因为你的预期结果图像不透明)所以在上面的代码中我将'mask'颜色设置为50%不透明度。