2010-12-22 76 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] == ""); 
    }