When the PNG thumbnail was generated, the background was black and today a function was written to make up for it. The code is simple, imagealphablending ($thumb, False), and Imagesavealpha ($thumb, true); It is important to save the alpha value of PNG, not to lose it.
| The code is as follows |
Copy Code |
? Php
/*
* $sourePic: Original path
* $smallFileName: Small map name
* $width: Small image width
* $heigh: Small picture height
* Reprinted Annotated Www.111cn.net * *
function Pngthumb ($sourePic, $smallFileName, $width, $heigh) {
$image =imagecreatefrompng ($sourePic);//png
Imagesavealpha ($image, true);//It's important to not lose the transparent color of the $sourepic image;
$BigWidth =imagesx ($image);//Large picture width
$BigHeigh =imagesy ($image);//Large picture height
$thumb = Imagecreatetruecolor ($width, $heigh);
Imagealphablending ($thumb, false);//Here is important, meaning does not merge the color, directly replaces with the $IMG image color, including the transparent color;
Imagesavealpha ($thumb, true);//Here is important, meaning do not lose the transparent color of the $thumb image;
if (imagecopyresampled ($thumb, $image, 0,0,0,0, $width, $heigh, $BigWidth, $BigHeigh)) {
Imagepng ($thumb, $smallFileName);}
return $smallFileName;//back to small map path}
Pngthumb ("A.png", "C.png", 300, 300);/call
?> |
All of the above we use PHP's own functions, not using any third-party programs, there is a need for friends to see OH.