php-仅在外部使白色透明
作者:互联网
我正在使用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);
但是,如果我上传某人牙齿洁白的照片,这会使他们的牙齿消失!那么,我是否错过了可以防止这种情况发生的事情,还是应该放弃这个想法?
解决方法:
多亏了我提出的解决方案的意见:
//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 );
只需让人们知道,紫红色与网站不兼容;)
标签:imagick,imagemagick,php 来源: https://codeday.me/bug/20191122/2061770.html