PHP PNG 24位清洁透明度

Chr*_*ris 3 php png transparency

我一直在尝试使用干净的24位alpha透明度上传PNG.经过大量的研究,我已经设法让它有点工作,但透明度似乎是低质量的8位,你可以在这个截图中看到:

http://cozomo.com/apple.png

任何有助于实现干净的PNG上传和24位平滑透明度调整的帮助将非常感激.我目前的代码如下.

if($extension=="png")
    {
        $uploadedfile = $_FILES['photo']['tmp_name'];
        $src = imagecreatefrompng($uploadedfile);
    }

        $dest_x = 1400; 
        $dest_y = 1200;

        if ($width > $dest_x or $height > $dest_y) { 

                if ($width >= $height) { 
                    $fullSize_x = $dest_x; 
                    $fullSize_y = $height*($fullSize_x/$width); 
                } else { 
                    $fullSize_x = $width*($fullSize_y/$height); 
                    $fullSize_y = $dest_y; 
                } 
        }

        $fullSize=imagecreatetruecolor($fullSize_x,$fullSize_y);

    //TEST
    $black = imagecolorallocate($fullSize, 0, 0, 0);
    imagecolortransparent($fullSize, $black);
    //TEST END

    // OUTPUT NEW IMAGES
    imagecopyresampled($fullSize,$src,0,0,0,0,$fullSize_x,$fullSize_y,$width,$height);

    imagepng($fullSize, "/user/photos/".$filename);

    imagedestroy($fullSize);


  [1]: http://i.stack.imgur.com/w8VBI.png
Run Code Online (Sandbox Code Playgroud)

Mus*_*usa 5

要保存您必须使用的完整Alpha通道,请imagesavealpha在保存png之前将其设置为

imagealphablending($fullSize, false);
imagesavealpha($fullSize, true);
Run Code Online (Sandbox Code Playgroud)