-
- imagecolorallocatealpha //Assign color + alpha
- imagesavealpha //Set to save complete alpha channel information when saving png images
Copy code
Full code:
-
-
- //Get the source image gd image identifier
- $srcImg = imagecreatefrompng('./src.png');
- $srcWidth = imagesx($srcImg);
- $srcHeight = imagesy ($srcImg);
- //Create a new image bbs.it-home.org
- $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');
Copy code
|