Make white transparent on the outside only

痴心易碎 提交于 2019-12-12 15:41:53

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/19120545/make-white-transparent-on-the-outside-only

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!