I’m trying to resize a PNG transparent image using the following code:
$src=ImageCreateFrompng($uploadedfile);
$background=imagecolorallocate($src,0,0,0);
imagecolortransparent($src,$background);
imagealphablending($src,false);
imagesavealpha($src,true);
$dst=ImageCreateTrueColor($tn_width,$tn_height);
imagecopyresampled($dst,$src,0,0,0,0,$tn_width,$tn_height,$width,$height);
Imagepng($dst,$dstfile);
I used imagealphablending($src,false) and imagesavealpha($src,true) but it still uploads an image with a black background instead of a transparent one.
Where’s the problem?
This is because you copy transparent image on a black one. Your false setting for aplhablending only applyes to original image, so when you copy on new image, aplha blending is turned on.
Your code needs just a little improvement:
OR JUST