簡體   English   中英

背景變黑了

[英]Background is turning out black

我做了一切我可能嘗試解決的問題。 我花了一個多小時研究和嘗試代碼,但沒有任何幫助。

此代碼執行以下操作。

  • 拍攝兩張完全白色的圖像並重新着色( 同時保持透明度
  • 將兩個圖像合並在一起
  • 輸出圖像(但一個黑色的背景!)

有人可以幫助識別和修補導致黑色背景的部分嗎? 有關腳本的示例,請參閱以下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

     $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); 

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM