I have a transparent png image. i'm trying to resize it using a function.
function resize_image($image, int $newWidth, int $newHeight) {
$newImage = imagecreatetruecolor($newWidth, $newHeight);
imagealphablending($newImage, false);
imagesavealpha($newImage,true);
$transparent = imagecolorallocatealpha($newImage, 255, 255, 255, 127);
imagefilledrectangle($newImage, 0, 0, $newWidth, $newHeight, $transparent);
$src_w = imagesx($image);
$src_h = imagesy($image);
imagecopyresampled($newImage, $image, 0, 0, 0, 0, $newWidth, $newHeight, $src_w, $src_h);
return $newImage;
}
But it still return a png with a colored background.
It seems it only works on transparent bakcground with opacity = 0. How can I solve the problem? I tried removing the two lines that reprocess the background, but it doesn't change anything.