2010-12-22 77 views
0

你好,我正在試圖結合兩個透明的png-24圖像,兩個大小400寬度,150高度。組合使用Php的2 png-24透明圖像

後臺: 「http://www.fenixflame.net/Background-Zanaris-24.png"][1]

我想覆蓋土坯背景圖像: [」 HTTP ://www.fenixflame.net/Bandos-Slayer-24.png「] [2]

我已經嘗試了使用php疊加透明圖像,但只有png-8圖像。由於圖片不能正確呈現,因此無法使用png-8。

編輯:代碼我tryed:

$image = imagecreatefrompng("http://www.fenixflame.net/Background-Zanaris-24.png"); 
$frame = imagecreatefrompng("http://www.fenixflame.net/Bandos-Slayer-24.png"); 
// 
//imagealphablending($frame,true); 
// 
$insert_x = imagesx($frame); 
    $insert_y = imagesy($frame); 
    imagecopymerge($image,$frame,0,0,0,0,$insert_x,$insert_y,100); 
// 
//# Save the image to a file imagepng($image, '/path/to/save/image.png'); 
imagepng($image, "/home1/fenixfla/public_html/Images/Signatures/NewImageBG.png"); 
// 
//# Output straight to the browser. 
imagepng($image); 
// 
+0

你在使用什麼庫? – yoda 2010-12-22 22:58:47

+0

我真的不知道,不是一個PHP的傢伙,如果有的話猜猜默認的那個? – Dangerosking 2010-12-22 23:02:17

回答

8

我寫的一個小例子在這個環節合併兩個透明圖像scitam.com

嘗試此代碼,它工作正常。

 

    $width = 200; 
    $height = 200; 

    $base_image = imagecreatefromjpeg("base.jpg"); 
    $top_image = imagecreatefrompng("top.png"); 
    $merged_image = "merged.png"; 

    imagesavealpha($top_image, true); 
    imagealphablending($top_image, true); 

    imagecopy($base_image, $top_image, 0, 0, 0, 0, $width, $height); 
    imagepng($base_image, $merged_image); 

2

使用GD庫來渲染圖像並在php中輸出。 http://www.php.net/manual/en/ref.image.php

之後變得非常多毛。你必須使用開始做的事情,如

imagealphablending($image, false); 
imagesavealpha($image, true); 

等,以確保透明度是正確的。

你可以看到我爲客戶端頁面here做的一個例子。這是非常乏味和巨大的痛苦。玩得開心

2

如何使用LIB ImageMagick的複合(http://www.imagemagick.org/script/composite.php)

function composite() { 
     $command = "/usr/local/bin/composite [... your properties...]"; 
     exec($command, $output, $result); 
     return ($result == 0 && $output[0] == ""); 
    }