2012-04-01 30 views
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); 

出力:PHP:透明な背景

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

は、どのように私は、 "ジョニー・ブラボー" に透明な背景を作ることができますか?コードの下

+0

は、同様に$背景画像上のアルファオプションを設定することを忘れないでください。 –

+0

@MarcBはあなたのanswear –

答えて

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); 
+0

出力は同じです。 。全体像は黒です:) –

+0

あなたの歓迎のためのおかげで、tihs –

+0

@DanielaRăducanuテスト私の編集コード –