2017-08-06 22 views
0

我是初学者,面临以下问题。我需要将两个imagefiles与imagemagick api合并 - >所以我使用php而不是comandline。如何合并imagemagick中的两个图像(php api)

我有一个BG: enter image description here

而且我有在中间的透明部分的图像: enter image description here

的Endresult应该是这样的: enter image description here

我会非常感谢,如果有人能帮我解决这个问题。我以数字方式尝试过,但没有任何成功。

回答

0

看看这个:http://phpimagick.com/Imagick/mergeImageLayers

我觉得这样的事情应该工作

function mergeImages() 
{ 
    // you should find the correct layerMethodType by yourself, 
    // here the available ones: http://php.net/manual/en/imagick.constants.php 

    $layerMethodType = imagick::LAYERMETHOD_COMPARECLEAR; 
    $img1 = new \Imagick(realpath("bg.png")); 

    $img2 = new \Imagick(realpath("play.png")); 
    $img1->addImage($img2); 
    $img1->setImageFormat('png'); 

    $result = $img1->mergeImageLayers($layerMethodType); 
    header("Content-Type: image/png"); 

    echo $result->getImageBlob(); 
} 
+0

THX我试过媒体链接这一个。没有输出/图像也没有错误。正如我想这个代码添加到我身边,我应该看到一个结果? – Jakob

+0

得到它现在工作thx – Jakob