在PHP-GD中将两个.png与透明度合并时的奇怪的透明度效果 [英] Odd transparency effect when merging two .png's with transparency in PHP-GD

查看:113
本文介绍了在PHP-GD中将两个.png与透明度合并时的奇怪的透明度效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

合并具有透明部分的两个图像将产生以下合成图像:

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();

推荐答案

GD在32位PNG中不支持透明性.您必须使用带有一种透明颜色"的8位或24位(正式的24位不支持透明,但是当使用保存为网络"和24位png时,Photoshop可以做到这一点.)

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).

这篇关于在PHP-GD中将两个.png与透明度合并时的奇怪的透明度效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆