我已经尽我所能尝试解决这个问题。我花了一个多小时研究和尝试代码,但没有任何帮助。
此代码执行以下操作。
- 拍摄两张全白图像并重新着色(同时保持透明度)
- 将两个图像合并在一起
- 输出图像(但背景为黑色!!)
有人可以帮助识别和修补导致黑色背景的部分吗?有关脚本示例,请参见以下 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);