2011-11-02 53 views
3

什麼看似簡單,是不是:(透明PNG超過JPG在PHP

我試圖像水印(透明的PNG)的圖像(JPG格式)上添加一些東西。 這是代碼我使用的是:

$width = 800; 
$height = 600; 
$bottom_image = imagecreatefromjpeg("portrait1.jpg"); 
$top_image = imagecreatefrompng("man2.png"); 
imagesavealpha($top_image, true); 
imagealphablending($top_image, true); 
imagecopy($bottom_image, $top_image, 200, 200, 0, 0, $width, $height); 
header('Content-type: image/png'); 
imagepng($bottom_image); 

當我合併圖像,PNG定位在正確的地方,上面everythig留下的是好(JPG被複制),但一切是黑色

我試過將imagesavealpha和imagealphablending設置爲false,沒有任何區別。

您可以在http://ekstrakt.selfip.com/photobomb/image.php

我已搜索周圍的網看到生成的圖像,我無法找到一個解決方案。

任何幫助表示讚賞。

+2

您還必須在$ bottom_image上啓用alphablending。 –

回答

3

$width$height應該是水印的大小,而不是照片。你要告訴它做的是複製水印的尺寸比它大得多。當它讀取不存在的圖像的一部分(座標超出邊界)時,結果是不透明的黑色,給出您看到的結果。