October 14th, 2009

Generation of the image

The author has offered the following algorithm: the complex{difficult} image in a picture is formed with the help of beforehand prepared substrates. Then on substrates the text, by a casual font, casual the size and, naturally, the casual maintenance{contents} is deduced.

The author has offered the following algorithm: the complex{difficult} image in a picture is formed with the help of beforehand prepared substrates. Then on substrates the text, by a casual font, casual the size and, naturally, the casual maintenance{contents} is deduced.

The basic lack of such algorithm consists that existing “substrate” can be calculated quickly. And after that to deduct from the image which is necessary for distinguishing and thus to receive a picture with the pure{clean} text. And for recognition of such text already today there is a weight of programs.

Our problem{task} – to make absolutely casual substrate, with the text which not that what to distinguish difficultly, it{him} to read hardly.

I would offer the following algorithm:

1. We create a substrate (for this purpose it is possible to use algorithm of construction of fractals)

2. We add handicapes – some casual lines, color of the body text.

3. We deduce{remove} the body text

4. The most interesting – we increase the image in rough quantity{amount} of times – for example, in 1.7, in 1.6

5. We reduce the image till the original sizes

To increase and reduce the image it is not necessary with use of smoothing, differently even the person can read the text.

If it seems to you that to draw a fractal too difficultly it is possible to draw a simple grid.

Principle of job of the mechanism

At call of the user on page with the form, we create session and we write down in the registered variable a casual code:

session_start ();

session_register (“secret_number”);

if (intval ($ _SESSION ["secret_number"]) <1000) {

srand (doubleval (microtime));

$ _SESSION ["secret_number"] =rand (1000,9999);

}

After the casual text is generated, it is necessary to deduce{remove} the form:

<form action = “index.php” method = “post”>

Yours E-Mail: <br>

<input type = “text” name = “email” value = “”> <br>

<br>

Enter a code which you see in a picture: <br>

<input type = “text” name = “secretcode” value = “”> <br>

<img src =’code.php? <? =doubleval (microtime ());?> ‘

width=101 height=26 vspace=5>

<br> <br>

<input type = “submit”>

</form>

The script processing the data, sent by means of the form, should work approximately as follows:

session_start ();

session_register (“secret_number”);

if ($ _SERVER ["REQUEST_METHOD"] == “POST”) {

$error=0;

if ($ _POST ["secretcode"]! = $ _SESSION ["secret_number"] ||

intval ($ _POST ["secretcode"]) == 0) $error=1;

if ($error == 0) {

$ _SESSION ["secret_number"] =rand (1000,9999);

// We carry out necessary actions with the data

//.

print “Hello” .htmlspecialchars (StripSlashes ($ _POST ["email"]));

exit;

}

if ($error == 1)

print ” <font color=red> the Number from a picture is entered incorrectly </font> “;

}

// We deduce{remove} the form repeatedly

//..

Generation of the image

<?

// We register a variable

session_start ();

session_register (“secret_number”);

function mt () {

list ($usec, $sec) = explode (‘ ‘, microtime ());

return (float) $sec + ((float) $usec * 100000);

}

header (” Content-type: image/png “);

// We create the image

$im=imagecreate (101, 26);

// We select color of a background (white)

$w=imagecolorallocate ($im, 255, 255, 255);

// We select color for a background (light grey)

$g1=imagecolorallocate ($im, 192, 192, 192);

// We select color for more dark handicapes (dark grey)

$g2=imagecolorallocate ($im, 64,64,64);

// We select four casual dark colors for symbols

$cl1=imagecolorallocate ($im, rand (0,128), rand (0,128), rand (0,128));

$cl2=imagecolorallocate ($im, rand (0,128), rand (0,128), rand (0,128));

$cl3=imagecolorallocate ($im, rand (0,128), rand (0,128), rand (0,128));

$cl4=imagecolorallocate ($im, rand (0,128), rand (0,128), rand (0,128));

// We draw a grid

for ($i=0; $i <=100; $i + = 5) imageline ($im, $i, 0, $i, 25, $g1);

for ($i=0; $i <=25; $i + = 5) imageline ($im, 0, $i, 100, $i, $g1);

// We deduce{remove} each figure separately, it is a little displacing casual image

imagestring ($im, 5, 0+rand (0,10), 5+rand (-5,5),

substr ($ _SESSION ["secret_number"], 0,1), $cl1);

imagestring ($im, 5, 25+rand (-10,10), 5+rand (-5,5),

substr ($ _SESSION ["secret_number"], 1,1), $cl2);

imagestring ($im, 5, 50+rand (-10,10), 5+rand (-5,5),

substr ($ _SESSION ["secret_number"], 2,1), $cl3);

imagestring ($im, 5, 75+rand (-10,10), 5+rand (-5,5),

substr ($ _SESSION ["secret_number"], 3,1), $cl4);

// We deduce{remove} a pair of casual lines of close color, it is direct atop of symbols.

// For increase in quantity{amount} of lines it is possible to increase,

// Having changed number selected with red color

for ($i=0; $i <8; $i ++)

imageline ($im, rand (0,100), rand (0,25), rand (0,100), rand (0,25), $g2);

// Factor of increase / reduction of a picture

$k=1.7;

// We create the new image, the increased size

$im1=imagecreatetruecolor (101 * $ k, 26 * $ k);

// We copy the image with change of the sizes in the big party{side}

imagecopyresized ($im1, $im, 0, 0, 0, 0, 101 * $ k, 26 * $ k, 101, 26);

// We create the new image, the normal size

$im2=imagecreatetruecolor (101,26);

// We copy the image with change of the sizes in the smaller party{side}

imagecopyresampled ($im2, $im1, 0, 0, 0, 0, 101, 26, 101 * $ k, 26 * $ k);

// We generate the image

imagepng ($im2);

// We release{exempt} memory

imagedestroy ($im2);

imagedestroy ($im1);

imagedestroy ($im);

?>

Like all. If something, leave comments.

Comments are closed.

footer

Design & programming by: Web Development Company CONKURENT LLC 2003-2009.