解决PHP剪切缩略图生成png,gif透明图时,黑色背景问题
2013-11-16 17:38 Saturday  

分类: PHP 标签: parent 图片 合并 id png 评论(81) 浏览(95320)

背景图填充白色背景

$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");

 

+1 22

留下你的看法: