在php中将png图片中的签名颜色更改为白色

在php中将png图片中的签名颜色更改为白色,php,Php,我有png格式的用户签名。我想把签名的颜色从黑色改为白色。我正在使用以下代码 $image = imagecreatefrompng('signature.png'); imagefilter($image, IMG_FILTER_COLORIZE, 255, 255, 255); // make it blue! imagepng($image, 'signature.png'); 但是背景变为黑色,我想因为使用imagecreatefrompng,我怎么能只更改签名的颜色。我使用了这段代码

我有png格式的用户签名。我想把签名的颜色从黑色改为白色。我正在使用以下代码

$image = imagecreatefrompng('signature.png');
imagefilter($image, IMG_FILTER_COLORIZE, 255, 255, 255); // make it blue!
imagepng($image, 'signature.png');

但是背景变为黑色,我想因为使用imagecreatefrompng,我怎么能只更改签名的颜色。

我使用了这段代码,它起作用了

$img = imagecreatefrompng('signature.png');
$background = imagecolorallocate($img, 0, 0, 0);
imagecolortransparent($img, $background);
imagealphablending($img, false);
imagesavealpha($img, true);

imagefilter($img, IMG_FILTER_COLORIZE, 255, 255, 255); // make it blue!

imagepng($img, 'signature.png')

嗨,瑞奇,是png上的阿尔帕频道,还是从一开始就是黑色的?您能为我们提供.png吗?提前谢谢你。你能退房吗?如果有效的话