$filename = 'data/output/test.png';
$image = imagecreatefrompng($filename);
$black = imageColorAllocate($image, 0, 0, 0);
$size = getimagesize($filename);
$w = $size[0];
$h = $size[1];
for ($x=0; $x < $w; $x++){
for ($y=0; $y < $h; $y++){
$color = imagecolorat($image, $x, $y);
$r = ($color >> 16) & 0xFF;
$g = ($color >> 8) & 0xFF;
$b = $color & 0xFF;
if ($r > 210 and $g > 210 and $b > 210){
imagesetpixel($image, $x , $y, $black);
}
}
}
imagecolortransparent($image, $black);
$res_path = 'data/output/result.png';
imagepng($image, $res_path, 9, NULL);
imagedestroy($image);