您好我正在尝试合并两个透明的png-24图像,尺寸均为400宽,150高度。
背景:[“http://www.fenixflame.net/Background-Zanaris-24.png”] [1]
我想覆盖的图像背景: [ “http://www.fenixflame.net/Bandos-Slayer-24.png”] [2]
我尝试使用php覆盖透明图像,但只使用png-8图像。由于图像无法正确渲染,因此无法使用png-8。
编辑:我尝试过的代码:
$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 :(得分: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);
答案 1 :(得分:2)
使用GD Library渲染图像并在php中输出。 http://www.php.net/manual/en/ref.image.php
之后变得非常毛茸茸。你必须使用开始做这样的事情
imagealphablending($image, false);
imagesavealpha($image, true);
以确保透明度正确。
您可以在首页here上看到我为客户做的事情的示例。这是超级乏味和巨大的痛苦。玩得开心
答案 2 :(得分: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] == "");
}
答案 3 :(得分:1)
您可能需要查看此内容:http://php.net/manual/en/function.imagecopymerge.php
imagecopymerge函数是PHP GD库的一部分。