$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”制作透明背景?
答案 0 :(得分: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);