2
$c = 'johnny-bravo.png'; //transparent bg
$imagesize = getimagesize($c);

$background = imagecreatefrompng('background.png'); //background
$char = imagecreatefrompng($c);

imagealphablending($char, false);
imagesavealpha($char, true);

imagecopymerge($background, $char, 260, 17, 0, 0, $imagesize[0], $imagesize[1], 100);

header('Content-type: image/png');

imagepng($background);
imagedestroy($background);

输出:

http://i.stack.imgur.com/0E7Lz.png

如何为“johnny-bravo”制作透明背景?

4

1 回答 1

0

使用下面的代码:

$c = 'johnny-bravo.png'; //transparent bg
$imagesize = getimagesize($c);

$tmp = @imagecreatetruecolor( $imagesize[0],  $imagesize[1] );
@imagealphablending( $tmp , false );
@imagesavealpha( $tmp , true );
$background = @imagecreatefrompng('background.png');

@imagecopyresampled( $tmp , $background , 0 , 0 , $imagesize[0] , $imagesize[1] , $imagesize[0] , $imagesize[1] );
$char = @imagecreatefrompng($c);
@imagecopyresampled($tmp , $char, 260, 17, 0, 0, $imagesize[0], $imagesize[1], 100);

header('Content-type: image/png');

imagepng($tmp);
imagedestroy($tmp);
于 2012-04-01T21:16:09.353 回答