This article mainly share with you the method of creating transparent PNG in PHP, hope to help everyone.
Certified as available, the code is as follows:
<?php/* * $sourePic: Original path * $smallFileName: Small map name * $width: Small image width * $heigh: Small figure high */function Pngthumb ($sourePic, $smallFileName, $width, $heigh) { $image = imagecreatefrompng ($sourePic);//png Imagesavealpha ($image, true);//It's important here to not lose the transparent color of $sourepic image ; $BigWidth =imagesx ($image);//Large image width $BigHeigh =imagesy ($image);//Large Image height $thumb = Imagecreatetruecolor ($width, $ Heigh); Imagealphablending ($thumb, false);//This is important, meaning that the color is not merged, directly replaced with the $img image color, including the transparent color; Imagesavealpha ($thumb, true);//Here is very important, meaning not to lose the transparent color of $thumb image; if (imagecopyresampled ($thumb, $image, 0,0,0,0, $width, $heigh, $BigWidth, $BigHeigh)) { imagepng ($thumb, $ smallfilename); } return $smallFileName;//Returns the small graph path}pngthumb ("001.png", "Test2.png", 300, 300);//Call echo ' <p style= ' Background-color: Red; " ></p> ";? >