【发布时间】:2012-12-18 06:55:30
【问题描述】:
可能重复:
Remove white background from an image and make it transparent
我目前有一个从图像中删除白色背景的代码,它看起来像这样:
function transparent_background($filename, $color)
{
$img = imagecreatefrompng($_SERVER['DOCUMENT_ROOT'].'/'.$filename);
$colors = explode(',', $color);
$remove = imagecolorallocate($img, $colors[0], $colors[1], $colors[2]);
imagecolortransparent($img, $remove);
imagepng($img, $_SERVER['DOCUMENT_ROOT'].'/'.$filename);
}
transparent_background('test.png', '255,255,255');
但是,一旦出口,边缘就非常粗糙。这就是它的样子(注意这只是我图片的一部分):
http://img211.imageshack.us/img211/97/2125c773e32c432b91e1127.png
我在该图像后面添加了黑色背景以更好地显示边缘。那么有没有办法可以在函数中添加一条线或编辑函数以使边缘更平滑/抗锯齿?谢谢!
【问题讨论】:
-
你的代码中没有画任何东西,会不会是原图中的粗边,只是因为没有深色背景而看不到?
-
@AndreKR 我的代码从我服务器上的特定 PNG 图像中删除了白色背景,并使白色背景透明。但是,输出边缘非常粗糙,我想知道是否有办法让它更平滑。
-
您可能会从我在这里的回答或同一问题的其他回答中得到一两个提示:stackoverflow.com/a/8042272/5987
标签: php function antialiasing