只在外面使白色透明 [英] Make white transparent on the outside only

查看:134
本文介绍了只在外面使白色透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用imagick与php修改上传的图像。我想删除图像周围的白色,使其具有透明背景。使用此:

I am using imagick with php to modify uploaded images. I want to remove the white around an image to make it have a transparent background. Using this:

$val = 65535/15;
$val = intval($val/1);//divide by 1 means accept full fuzz at the moment
$image->paintTransparentImage("rgb(255,255,255)", 0.0, intval(1*$val); 

但是,如果我上传一张牙齿洁白的人的图片,牙齿消失!所以我错过了一些我可以做的事情来防止这种情况或者我应该放弃这个想法吗?

However, if I upload a picture of someone with white teeth, it makes their teeth vanish! So am i missing something that I could do to prevent that or should I just drop the idea?

推荐答案

感谢我提出这个解决方案的评论:

Thanks to the comments I came up with this solution:

//15 is the degree of fuzz user can choose in page
$val = 65535/15;
//divide by fuzz dilution, 1 is none
$val = floatval($val/1);
//create white border
$image->borderImage ( "rgb(255,255,255)" , 1 , 1 );
//make all white fill fuchsia 
$image->floodFillPaintImage ( "rgb(255, 0, 255)" ,$userfuzz*$val, "rgb(255,255,255)", 0 , 0, false);
//make fuchsia transparent
$image->paintTransparentImage("rgb(255,0,255)", 0.0, 10); 
//remove border 1px that was added above
$image->shaveImage ( 1 , 1 );    

只需让人们知道紫红色与网站不兼容;)

Just have to let people know that fuchsia is incompatible with the website ;)

这篇关于只在外面使白色透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆