繁体   English   中英

PHP:透明背景

[英]PHP: Transparent background

$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”具有透明背景?

使用以下代码:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM