I have been trying to get a PNG to upload with a clean, 24 bit alpha transparency. After doing a lot of research, I have managed to get it sort of working, however the transparency seems to be low quality 8 bit as you can see here in this screenshot:
Any help to achieve a clean PNG upload and resize with 24 bit smooth transparency would be much appreciated. My current code is below.
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]: https://i.stack.imgur.com/w8VBI.png