> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; $gs = (($r*0.299)+($g*0.587)+($b*0.114)); if ( $gs > 150 ) { $map[$x][$y] = 1; } else { $map[$x][$y] = 0; } } } if(!is_array($threshold)) { $thresholds = (array) $thresholds; foreach($thresholds as $threshold) { $rem = array(); for($x=0;$x<$width; $x++) { for($y=0;$y<$height; $y++) { if($map[$x][$y] > 0) { $n = 0; if($map[$x-1][$y] > 0) $n++; if($map[$x-1][$y-1] > 0) $n++; if($map[$x-1][$y+1] > 0) $n++; if($map[$x+1][$y] > 0) $n++; if($map[$x+1][$y-1] > 0) $n++; if($map[$x+1][$y+1] > 0) $n++; if($map[$x][$y-1] > 0) $n++; if($map[$x][$y+1] > 0) $n++; if($n < $threshold) $rem[$x][$y] = 0; } } } for($x=0;$x<=$width; $x++) { for($y=0;$y<$height; $y++) { if(isset($rem[$x][$y])) $map[$x][$y] = 0; } } } $img2 = imagecreate($width, $height); $b = imagecolorallocate( $img2, 0, 0, 0 ); $w = imagecolorallocate( $img2, 255, 255, 255 ); $n=0; for($x=0;$x<$width; $x++) { for($y=0;$y<$height; $y++) { if($map[$x][$y] > 0) imagesetpixel($img2,$x,$y,$w); } } if($return) { return $img2; } else { imagepng($img2,'clean-'.$filename); } } ?>