PHP 合并两张图片创建粉红色阴影
PHP merging two images creates a pink shade
我正在尝试使用下面的 PHP 代码合并两个图像:
$image1=imagecreatefrompng($url1);
$image2=imagecreatefrompng($url2);
$final = imagecreatetruecolor($w, $h);
$backgroundColor = imagecolorallocate($final, 255, 255, 255);
imagefill($final, 0, 0, $backgroundColor);
imagecopy($final, $image1, 0,0,0,0,$w,$h);
imagecopy($final, $image2, 0,0,0,0,$w,$h);
合并后,生成的图像出现粉红色阴影。请帮忙。我该如何解决?
原始图片:
生成的合并图像:
我已经用你的图片试过你的代码link
它运作良好并生成适当的png
供大家参考
$url1 = 'http://i.stack.imgur.com/kDYTM.png';
$url2 ='http://i.stack.imgur.com/MKTcb.png';
$image1=imagecreatefrompng($url1);
$image2=imagecreatefrompng($url2);
$final = imagecreatetruecolor(275, 275);
$backgroundColor = imagecolorallocate($final, 255, 255, 255);
imagefill($final, 0, 0, $backgroundColor);
imagecopy($final, $image1, 0,0,0,0,275,275);
imagecopy($final, $image2, 0,0,0,0,275,275);
header('Content-type:image/png');
imagepng($final);
对于 gif 图片,您可以将最后两行替换为
header('Content-type:image/gif');
imagegif($final);
您的目标图像是 GIF,仅限于 256 色调色板。尝试导出为 JPG 或 PNG,您可能会获得更好的色彩保真度。
我正在尝试使用下面的 PHP 代码合并两个图像:
$image1=imagecreatefrompng($url1);
$image2=imagecreatefrompng($url2);
$final = imagecreatetruecolor($w, $h);
$backgroundColor = imagecolorallocate($final, 255, 255, 255);
imagefill($final, 0, 0, $backgroundColor);
imagecopy($final, $image1, 0,0,0,0,$w,$h);
imagecopy($final, $image2, 0,0,0,0,$w,$h);
合并后,生成的图像出现粉红色阴影。请帮忙。我该如何解决?
原始图片:
生成的合并图像:
我已经用你的图片试过你的代码link 它运作良好并生成适当的png 供大家参考
$url1 = 'http://i.stack.imgur.com/kDYTM.png';
$url2 ='http://i.stack.imgur.com/MKTcb.png';
$image1=imagecreatefrompng($url1);
$image2=imagecreatefrompng($url2);
$final = imagecreatetruecolor(275, 275);
$backgroundColor = imagecolorallocate($final, 255, 255, 255);
imagefill($final, 0, 0, $backgroundColor);
imagecopy($final, $image1, 0,0,0,0,275,275);
imagecopy($final, $image2, 0,0,0,0,275,275);
header('Content-type:image/png');
imagepng($final);
对于 gif 图片,您可以将最后两行替换为
header('Content-type:image/gif');
imagegif($final);
您的目标图像是 GIF,仅限于 256 色调色板。尝试导出为 JPG 或 PNG,您可能会获得更好的色彩保真度。