3

我正在使用 imagick 和 php 来修改上传的图像。我想删除图像周围的白色以使其具有透明背景。使用这个:

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

但是,如果我上传一张牙齿洁白的人的照片,它会使他们的牙齿消失!那么我是否错过了一些我可以做的事情来防止这种情况发生,或者我应该放弃这个想法?

4

1 回答 1

3

感谢评论我想出了这个解决方案:

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

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

于 2013-10-01T16:47:34.637 回答