2012-04-01 179 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

不要忘記設置$背景圖像上的字母選項,以及。 – 2012-04-01 21:28:21

+0

@MarcB與「$背景」完成但仍然相同的輸出 – 2012-04-01 21:31:53

回答

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

輸出是相同的..謝謝你的answear – 2012-04-01 21:18:58

+0

歡迎您,請w8修復tihs – 2012-04-01 21:20:08

+0

@DanielaRăducanu測試我的編輯代碼 – 2012-04-01 21:25:45