php - Background is turning out black -
i have done possibly try fix this. i've spent on hour researching , trying code, nothing has helped.
this code following.
- take 2 completely-white images , re-color them (while keeping transparency)
- merge 2 images together
- outputs images (but with black background!!)
can identify , patch part that's causing black background? see following url example of script.
-
$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
false, fill image transparent color, set imagealphablending
true, copying stuff.
$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 code
Comments
Post a Comment