[英]Background is turning out black
I have done everything I could possibly try to fix this. 我做了一切我可能尝试解决的问题。 I've spent over an hour researching and trying code, but nothing has helped.
我花了一个多小时研究和尝试代码,但没有任何帮助。
This code does the following. 此代码执行以下操作。
Can someone help identify and patch the part that's causing the black background? 有人可以帮助识别和修补导致黑色背景的部分吗? See the following URL for an example of the script.
有关脚本的示例,请参阅以下URL。
http://labs.bluefiremedia.net/metro-machine/gd/download-png.php?size=128&padding=29&icon=icons/Application/Add-New.png&bgShape=CircleBG.png&bgColorR=255&bgColorG=0&bgColorB=0&iconColorR=255&iconColorG=255&iconColorB=255 http://labs.bluefiremedia.net/metro-machine/gd/download-png.php?size=128&padding=29&icon=icons/Application/Add-New.png&bgShape=CircleBG.png&bgColorR=255&bgColorG=0&bgColorB=0&iconColorR=255&iconColorG= 255&iconColorB = 255
$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);
Set imagealphablending
to false, fill your image with a transparent color, set imagealphablending
to true, then do your copying stuff. 将
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.