A PNG picture with a transparent color that shrinks as a JPG results in a transparent color loss. So what can I do to save a transparent color? The following code can solve this problem
The main use of the GD library two methods: The code is as follows: Imagecolorallocatealpha//Assign color + Alpha Imagesavealpha//Set Save the PNG image with the complete alpha channel Information code example: The code is as follows://Get source map GD image identifier $SRCIMG = Imagecreatefrompng ('./src.png '); $srcWidth = Imagesx ($SRCIMG); $srcHeight = Imagesy ($SRCIMG); Create a new diagram $newWidth = round ($srcWidth/2); $newHeight = Round ($srcHeight/2); $NEWIMG = Imagecreatetruecolor ($newWidth, $newHeight); Assign color + Alpha to fill the new image $alpha = Imagecolorallocatealpha ($newImg, 0, 0, 0, 127); Imagefill ($newImg, 0, 0, $alpha); Copy the source diagram to the new diagram and set the full alpha channel information to be saved when the PNG image is saved imagecopyresampled ($NEWIMG, $srcImg, 0, 0, 0, 0, $newWidth, $newHeight, $srcWid th, $srcHeight); Imagesavealpha ($NEWIMG, true); Imagepng ($NEWIMG, './dst.png ');