|
Новичок
Регистрация: 25.11.2007
Сообщений: 8
Провел на форуме: 20866
Репутация:
0
|
|
Автору спасибо, на основе его и Nomer'овского кода решил свои маленькие проблемы с одним надоедливым сервисом.
Распознает капчу из букв и цифр типа
PHP код:
<?
//coded by rikki
function pwntcha($image) {
define("LETTERS" , "...##.....####...##..##.##....####....####....############....####....####....########..##...##.##....####...##.######..##...##.##....####....####...##.######....#####..##...####.....###......##......##......##......##.....#.##...##..#####.######..##...##.##....####....####....####....####....####....####...##.######..#######.##......##......##......######..##......##......##......##......#######.##########......##......##......######..##......##......##......##......##........#####..##...####......##......##......##...#####....####....##.##...##..#####.##....####....####....####....############....####....####....####....####....##################################################################################...####......##......##......##......##......##......##..#...##..##.##....###...##....####...##.##..##..##.##...####....####....##.##...##..##..##...##.##....####......##......##......##......##......##......##......##......##......#######.##....#####..#############.##.####.##.####.##.####....####....####....####....####....#####...######..######..####.##.####.##.####..######...#####...#####....##................................................................................#######.##....####....####....#########.##......##......##......##......##........####...##..##.##....####....####....####....####.##.####..####.##..##...####.########.##....####....####....#########.#####...##..##..##...##.##....####....##.######.##....####......##.......######.......##......##......####....##.######.########...##......##......##......##......##......##......##......##......##...##....####....####....####....####....####....####....####....##.##..##...####..##....####....####....##.##..##..##..##..##..##...####....####.....##......##...##....####....####....####....####.##.####.##.####.##.#############..#####....####....####....##.##..##...####.....##......##.....####...##..##.##....####....####....####....##.##..##...####.....##......##......##......##......##......##...#######......##......##.....##.....##.....##.....##.....##......##......#######...####...##..##.##....##......##.....##.....##.....##.....##.....##.....########.#####..##...##.......##.....##....###.......##.......##......####...##..#####.......##.....###....####...##.##..##..##.##...##.########.....##......##......##.#######.##......##......##.###..###..##.......##......####....##.##..##...####....####...##..##.##....#.##......##.###..###..##.##....####....##.##..##...####..########......##......##.....##.....##.....##.....##.....##.....##......##........####...##..##.##....##.##..##...####...##..##.##....####....##.##..##...####....####...##..##.##....####....##.##..###..###.##......##.#....##.##..##...####..
");
define("CSE", rand(1,10)>5?65:97); //randomly define CASE of captcha value at runtime. Don't wanna leave a pattern.
$tempname = tempnam("./", "cap");
$temp = fopen($tempname, "w");
fwrite($temp, $image);
fclose($temp);
$src = imagecreatefromjpeg($tempname);
$im = imagecreatetruecolor(53, 10);
imagecopy($im, $src, 0, 0, 5, 11, 53, 10);
$bl = imagecreatetruecolor(8, 10);
$txtNum = '';
for($n = 0; $n<48; $n += 9) {
imagecopy($bl, $im, 0, 0, $n, 0, 8, 10);
$txtNum .= charcode($bl);
}
unlink($tempname);
return $txtNum;
}
function charcode($cell) {
$white = imagecolorallocate($cell, 255, 255, 255); //$cell must be truecolor, otherwise OOL
$black = imagecolorallocate($cell, 0, 0, 0); //-/- applies :P
$linear='';
for($j=0;$j<10;$j++)
{
for($i=0;$i<8;$i++)
{
$color=imageColorAt($cell,$i,$j);
list($r,$g,$b) = array_values(imageColorsForIndex($cell,$color));
if($r>40 && $g>40 && $b>40)
{
imagesetpixel($cell,$i,$j,$white); //what we do here is we map the image pixel by pixel onto a string
$linear .= '.';//echo "."; //with binary values of # == "I am a pixel that's part of a letter" and . == "I am useless and irrelevant"
} else {
imagesetpixel($cell,$i,$j,$black);
$linear .= '#';//echo "#";
}
}
//echo "\n\r";
}
$char = strpos(LETTERS, $linear);
if ($char < 2075) {return(chr(CSE + $char/80));}
else {return(chr(50 + ($char/80)-26 ));}
}
?>
Последний раз редактировалось Johan; 17.04.2008 в 23:39..
|