【问题标题】:Odd transparency effect when merging two .png's with transparency in PHP-GD在 PHP-GD 中合并两个具有透明度的 .png 时出现奇怪的透明度效果
【发布时间】:2011-07-01 23:42:55
【问题描述】:

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

我想知道为什么我覆盖在绿色背景上的图像的透明部分会这样显示?有人吗?

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

【问题讨论】:

标签: php png gd alphablending


【解决方案1】:

GD 不支持 32 位 PNG 的透明度。您必须使用带有一种透明“颜色”的 8 位或 24 位(官方称 24 位不支持透明度,但 Photoshop 可以在使用带有 24 位 png 的“保存为网络”时做到这一点)。

【讨论】:

    猜你喜欢
    • 2011-10-14
    • 2019-08-13
    • 1970-01-01
    • 2012-04-05
    • 2012-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多