本文介绍了PNG有黑色背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用一个lib来轻松保存图像.
I'm using a lib to easy save images.
http://www.white -hat-web-design.co.uk/blog/resizing-images-with-php/
但是问题在于它使用黑色背景保存了透明的png.我搜索了一下,发现了应该起作用但对我不起作用的东西.
But the problem is that it saves transparant png with black background. I have search and found something that should work but is not working for me.
imagecolortransparent()通常应该这样做.但是对我来说,我仍然看到黑色的背景.
imagecolortransparent() should normally do it.But for me I still see the black background.
我做错了什么?
$imagename = $_FILES['file']['name'];
$target = "source/images/".$imagename;
$image->save($target);
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null){
if( $image_type == IMAGETYPE_PNG ){
$image = $this->image;
$black = imagecolorallocate($image, 0, 0, 0);
imagecolortransparent($image, $black);
imagepng($image,$filename);
}
}
推荐答案
您可能应该更改
$black = imagecolorallocate($im, 0, 0, 0);
到
$black = imagecolorallocate($image, 0, 0, 0);
尝试设置图像Alpha混合
Try setting image alpha blending
imagealphablending($image, false);
imagesavealpha($image, true);
这篇关于PNG有黑色背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!