$threshold) { imagesetpixel($captcha,$x,$y,255); } else { imagesetpixel($captcha,$x,$y,0); $blackPixels[] = array($x,$y); } } } foreach($blackPixels as $blackPixel) { imagesetpixel($captcha,$blackPixel[0]+1,$blackPixel[1]+1,0); imagesetpixel($captcha,$blackPixel[0],$blackPixel[1]+1,0); imagesetpixel($captcha,$blackPixel[0],$blackPixel[1]-1,0); imagesetpixel($captcha,$blackPixel[0]+1,$blackPixel[1],0); imagesetpixel($captcha,$blackPixel[0]-1,$blackPixel[1],0); imagesetpixel($captcha,$blackPixel[0]+1,$blackPixel[1]-1,0); imagesetpixel($captcha,$blackPixel[0]-1,$blackPixel[1]+1,0); imagesetpixel($captcha,$blackPixel[0]-1,$blackPixel[1]+1,0); } $startedCharacter = False; $highestY = 10000; $lowestY = 0; $count = 0; for($x=0;$x<$width;$x++) { $hasBlack = False; for($y=0;$y<$height;$y++) { if(imagecolorat($captcha,$x,$y) == 0) { $hasBlack = True; if($y<$highestY){ $highestY = $y; } if($y>$lowestY){ $lowestY = $y; } $eax = $y; if(!$startedCharacter) { $data["x1"] = $x; $data["y1"] = $y; $startedCharacter = True; } } } if(($startedCharacter) && (!$hasBlack)) { $data["x2"] = $x; $data["y2"] = $eax; $newWidth = $data["x2"] - $data["x1"]; $newHeight = $lowestY - $highestY; $croppedLetter = imagecreate($newWidth,$newHeight); imagecopy($croppedLetter,$captcha,0,0,$data["x1"],$highestY,$width,$newHeight); $captchas[] = $croppedLetter; imagepng($croppedLetter,"tmp-$count.png"); //imagerectangle($captcha,$data["x1"],$lowestY,$data["x2"],$highestY,"#FFFFFF"); $startedCharacter = False; $highestY = 10000; $lowestY = 0; $count++; } } $i=0; foreach(glob("phpbb-captcha/*.png") as $imageValue) { $images[$i]["resource"] = imagecreatefrompng($imageValue); $images[$i]["path"] = $imageValue; $i++; } foreach($captchas as $captcha){ $bestFit = 0; $height = imagesy($captcha); $width = imagesx($captcha); for($i=0;$i $bestFit){ $bestFit = $sum; $char=$images[$i]["path"];} } preg_match("@/([\d\w])@",$char,$match); echo $match[1]; } ?>