PHP-使用imagecopy时颜色不正确
我有几个png图像,它们是这样生成的:PHP-使用imagecopy时颜色不正确,php,gd,Php,Gd,我有几个png图像,它们是这样生成的: $img = imagecreatefrompng($full_path_to_file); imagealphablending($img , true); // setting alpha blending on imagesavealpha($img , true); // save alphablending setting 这些图像效果很好,颜色合适,背景透明 我需要将这些图像合并成一个。为此,我做了以下工作: 创建具有正确尺寸的空白图像 $f
$img = imagecreatefrompng($full_path_to_file);
imagealphablending($img , true); // setting alpha blending on
imagesavealpha($img , true); // save alphablending setting
这些图像效果很好,颜色合适,背景透明
我需要将这些图像合并成一个。为此,我做了以下工作:
$full\u image=imagecreate($full\u width,$full\u height)代码>
imagecopy($full\u image,$src,$dest\u x,$dest\u y,0,0,$src\u width,$src\u height
)
图像组合正常。背景是透明的,但是颜色不正确
我如何确保得到正确的颜色
更新:按照建议,修复方法是使用imagecreatetruecolor
此外,我需要将第二个参数设置为imagealphabling
为false。因此,当创建png图像并创建完整图像时,我调用
imagealphablending($img , false); // updated to FALSE
imagesavealpha($img , true);
文件:
您必须将alphablending(imagealphablending($im,false))取消设置为
使用它
尝试使用:而不是imagecreate。只需在调用imagecopy()方法后添加以下代码 $white=imagecolorallocate($destination\u image,255,255);
imagefill($destination_image,0,0,$white) 你能告诉我们你说的“不正确”是什么意思吗?你用你没有CMYK文件吗?你不会是第一个尝试的人。我什么也没做。imagecreatetruecolor适用于jpegsDid。您可以尝试imagecopymerge将两个PNG合并到创建的imagecreatetruecolor上,然后用imagepng?1秒输出。实际上我再次尝试了
imagecreatetruecolor
,这次它给了我正确的颜色,但背景是黑色而不是透明的。在imagecreatetruecolor创建的图像上使用图像alpha。这样就可以了。需要将alpha混合设置为false。更新答案,提供更多详细信息