背景图填充白色背景
$white = imagecolorallocate($dstim,255,255,255);
imagefilledrectangle($dstim,0,0,$width,$height,$white);
imagecolortransparent($dstim,$white);
设置图片走透明通道
$img = imagecreatefrompng($src);
imagesavealpha($img,true);//这里很重要;
$thumb = imagecreatetruecolor(300,300);
imagealphablending($thumb,false);//这里很重要,意思是不合并颜色,直接用$img图像颜色替换,包括透明色;
imagesavealpha($thumb,true);//这里很重要,意思是不要丢了$thumb图像的透明色;
imagecopyresampled($thumb,$img,0,0,0,0,300,300,300,300);
imagepng($thumb,"temp.png");