Copy an Image with Drop Shadow and Tranparent Background
I tried to duplicate a PNG image, which has drop shadow (i.e. alpha channel) and transparent background. However, the resulting image paints the shadow and transparent background with black. I tried with imagecopy
and imagecopymerge
; neither yielded to valid results, which aren't the same with the original image.
Preview of开发者_如何学JAVA the images.
$src = imagecreatefrompng('img_box3-bg.png');
/* Using imagecopy. */
$dest = imagecreatetruecolor(116, 100);
imagecopy($dest, $src, 0, 0, 0, 0, 116, 100);
imagepng($dest, 'img_box3-bg.imagecopy.png');
imagedestroy($dest);
/* Using imagecopymerge. */
$dest2 = imagecreatetruecolor(116, 100);
imagecopymerge($dest2, $src, 0, 0, 0, 0, 116, 100, 100);
imagepng($dest2, 'img_box3-bg.imagecopymerge.png');
imagedestroy($dest2);
imagedestroy($src);
Help? Thanks beforehand.
Something like this:
$src = imagecreatefrompng('img_box3-bg.png');
/* Using imagecopy. */
$dest = imagecreatetruecolor(116, 100);
// this is new
imagesavealpha($dest, true);
$transparent = imagecolorallocatealpha($dest, 0, 0, 0, 127);
imagefill($dest, 0, 0, $transparent);
imagecopy($dest, $src, 0, 0, 0, 0, 116, 100);
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
精彩评论