在PHP中合并两个具有透明度的图像

| 我正在尝试通过php制作具有背景透明性的几个.png \的合成图像,并将结果图像存储在我的数据库中。我的问题是合并图像时,图像的透明部分会被丢弃。 这是我创建合成图像的代码:
    $base = imagecreatefrompng(\'application/assets/images/vel1_bg.png\');
    imagealphablending($base, true);
    list($baseWidth, $baseHeight, $type, $attr) = getimagesize(\'application/assets/images/vel1_bg.png\');

    $user_board_items = $this->config->item(\'user_board_items\');

    foreach($array as $key => $value){
        $item = imagecreatefrompng(\'application/assets/images/items/\' . $user_board_items[$value[0]] . \'.png\');         
        imagealphablending($item, true);
        list($width, $height, $type, $attr) = getimagesize(\'application/assets/images/items/\'. $user_board_items[$value[0]] . \'.png\');

        imagecopymerge($base,
                    $item,
                    floor(($value[1] / 100) * $baseWidth),
                    floor(($value[2] / 100) * $baseHeight),
                    0,
                    0,
                    $width,
                    $height,
                    100);
        imagedestroy($item);
    }

    //We have to capture the output buffer
    ob_start();
    imagepng($base);
    $baseimg = ob_get_clean();
这将产生如下图像: 我正在寻找更像这样的东西: (请注意透明部分的表示方式)     
已邀请:
        不要使用imagecopymerge()合并透明图像。 最好在脚本中使用imagecopyresampled()。     
        如前所述,经过数小时尝试不同的解决方案后,imagecopyresampled也对我有用。要传递的参数保持不变,除了必须删除最后一个参数外,还要添加源的宽度和高度。您的电话可能是:
  imagecopyresampled($base,
                $item,
                floor(($value[1] / 100) * $baseWidth),
                floor(($value[2] / 100) * $baseHeight),
                0,
                0,
                $width,
                $height,
                $width,
                $height);
    

要回复问题请先登录注册