Odd transparency effect when merging two .png's with transparency in PHP-GD

╄→尐↘猪︶ㄣ 提交于 2019-12-25 17:03:26

问题


Merging two images with transparent sections produces the following composite image:

I'm wondering why the transparent section of the image I've overlayed onto the green background shows up as such? Anyone?

$base = imagecreatefrompng('application/assets/images/vel1_bg.png');
        imagealphablending($base, false);
        imagesavealpha($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, false);
            imagesavealpha($item, true);    
            list($width, $height, $type, $attr) = getimagesize('application/assets/images/items/'. $user_board_items[$value[0]] . '.png');

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

            imagedestroy($item);
        }

        //We have to capture the output buffer
        ob_start();
        imagepng($base);
        $baseimg = ob_get_clean();

回答1:


GD does not support transparency in 32-bit PNG. You have to use either 8-bit with one transparent 'color' or 24-bit (officially 24-bit does not support transparency, but Photoshop can do it when using 'save for web' with 24bit png).



来源:https://stackoverflow.com/questions/6496119/odd-transparency-effect-when-merging-two-pngs-with-transparency-in-php-gd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!