Mainly use two methods of the gd library:
imagesavealpha //Set to save complete alpha channel information when saving png images
Code example:
//Create a new image
$newWidth = round($srcWidth / 2);
$newHeight = round($srcHeight / 2);
$newImg = imagecreatetruecolor($newWidth, $newHeight) ;
//Assign color + alpha, fill the color onto the new image
$alpha = imagecolorallocatealpha($newImg, 0, 0, 0, 127);
imagefill($newImg, 0, 0, $alpha);
//Copy the source image to the new image, and set it to save the complete alpha channel information when saving the PNG image
imagecopyresampled($newImg, $srcImg, 0, 0, 0, 0, $newWidth, $ newHeight, $srcWidth, $srcHeight);
imagesavealpha($newImg, true);
imagepng($newImg, './dst.png');