我已尽我所能解决这个问题。我花了一个多小时研究和尝试代码,但没有任何帮助。
此代码执行以下操作。
有人可以帮助识别和修补导致黑色背景的部分吗?有关脚本的示例,请参阅以下URL。
$final_image = imagecreatetruecolor($dimensions, $dimensions);
imagesavealpha($final_image, true);
if($bgShape != '') {
list($originalWidth, $originalHeight) = getimagesize('../images/' . $bgShape);
$background = imagecreatefrompng('../images/' . $bgShape);
imagefilter($background, IMG_FILTER_BRIGHTNESS, -255);
imagefilter($background, IMG_FILTER_COLORIZE, $bgColorR, $bgColorG, $bgColorB);
$backgroundImage = imagecreatetruecolor( $dimensions, $dimensions );
imagealphablending($backgroundImage , false);
imagesavealpha($backgroundImage , true);
imagecopyresampled($backgroundImage,
$background,
0, 0,
0, 0,
$dimensions, $dimensions,
$originalWidth, $originalHeight
);
imagecopy($final_image, $backgroundImage, 0, 0, 0, 0, $dimensions, $dimensions);
///
$icon = imagecreatefrompng("../" . $icon);
imagefilter($icon, IMG_FILTER_BRIGHTNESS, -255);
imagefilter($icon, IMG_FILTER_COLORIZE, $iconColorR, $iconColorG, $iconColorB);
$iconImage = imagecreatetruecolor( $dimensions, $dimensions );
imagealphablending($iconImage , false);
imagesavealpha($iconImage , true);
imagecopyresampled($iconImage,
$icon,
0, 0,
0, 0,
$dimensions, $dimensions,
$originalWidth, $originalHeight
);
imagecopy($final_image, $iconImage, 0, 0, 0, 0, $dimensions, $dimensions);
///
imagealphablending($final_image, true);
imagesavealpha($final_image, true);
imagepng($final_image, NULL, 0, PNG_NO_FILTER);
header("Content-type: image/png");
imagedestroy($backgroundImage);
答案 0 :(得分:2)
将imagealphablending
设置为false,用透明色填充图像,将imagealphablending
设置为true,然后复制内容。
$final_image = imagecreatetruecolor($dimensions, $dimensions);
imagealphablending($final_image, false);
$transparency = imagecolorallocatealpha($final_image, 0, 0, 0, 127);
imagefilledrectangle($final_image, 0, 0, $dimensions, $dimensions, $transparency);
imagesavealpha($final_image, true);
imagealphablending($final_image, true);
// rest of the code