 |
 |
Captcha: K5ANAO
|
 |
<?php
require_once('../gd2imaging.php');
// load an image with a reference alphabet characters
$charsImage = new Image('alphabet.png');
// set size of the reference characters
$charSize = new Dimensions(26, 25);
// create the quantizator
$quantizator = new Quantizator();
foreach(array_merge(range('A', 'Z'), range(1, 9)) as $index => $char) {
// fetch an image of the given character
$charImage = $charsImage->getSubImage(new Point($index * 26, 0), $charSize);
// add vector to the glyphs collection
$quantizator->addGlyph($charImage->getVector(), $char);
}
// load captcha text to read
$image = new Image('captcha.gif');
// invert colors, remove captcha noise
$image->toNegative()->useMedian();
$text = '';
$lastObject = null;
// try to find all letters and numbers in the captcha.
foreach($image->findObjects() as $object) {
$lastObject = $object;
$search = $object->resize($charSize)->getVector();
$result = $quantizator->findNearestEuklid($search);
$text .= $result[0];
}
echo 'Captcha: <strong>'.$text.'</strong><br>';
|