php证件照换底色、php人像抠图、php换背景图
代码如下:
';
}
function cleancolor($imgid,$color){
$width = imagesx($imgid);//获取宽
$height = imagesy($imgid);//获取高
for($i=0;$i<$width;$i++){
for($k=0;$k<$height;$k++){
//对比每一个像素
$rgb = imagecolorat($imgid,$i,$k);
$r = ($rgb >> 16)&0xff;//取R
$g = ($rgb >> 8)&0xff;//取G
$b = $rgb&0xff;//取B
$randr = 1.5;
$randg = 1;
$randb=1;
//蓝色RGB大致的位置。替换成绿色
if($r<=65*$randr && $g<=225*$randg && $b<=255*$randb && $b*$randb>=100){
//如果能够精确的计算出要保留位置的,这里可以写绝对的数字
if($i>=$width/2 && $i<=$width/2 && $k>=$height/2 && $k<=$height/2){
}else{
//改变颜色
imagesetpixel($imgid,$i,$k,$color);
}
}
}
}
}$old指的是要处理的图片,指定为png格式 $new指的是处理后输出的图片名 $bg指的是背景图
Author:TANKING
Date:2020-05-07
Web:http://www.likeyunba.com/
WeChat:face6009



