Unusual result when merging two transparent images in php

瘦欲@ 提交于 2019-12-06 07:48:46

Try the following code its working fine.


    $width = 95;
    $height = 111;

    $base_image = imagecreatefrompng("../guy.png");
    $top_image = imagecreatefrompng("../frame.png");

    imagesavealpha($top_image, false);
    imagealphablending($top_image, false);
    imagecopy($base_image, $top_image, 0, 0, 0, 0, $width, $height);
    imagepng($base_image, "merged.png");

I think that Jaguar library which uses GD will help to do that easily:

for example to create what you want you need to use the overlay action which works with gif,png,jpeg and any supported format:

Note This action is super fast and is not pixel based and the overlay could be any supported format and the opacity will be saved

use Jaguar\Canvas,
    Jaguar\Transformation;

$transformation = new Transformation(new Canvas('your robots'));
$transformation->overlay(new Canvas('your frame'))
           ->getCanvas()
           ->show();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!