Location: PHPKode > scripts > Orca Ringmaker > orca-ringmaker/orm3/captcha.php
<?php /* ***** Orca Ringmaker - CAPTCHA Generator ******************* */


/* ***** User tweak variables *************************************** */
$font = './fonts/DAYROM__.ttf';
$size = 20;










/* ***** Create Image *********************************************** */
header("Content-type: image/png");

require "config.ini.php";

$_DDATA['online'] = false;
if ($_DDATA['link'] = @mysql_connect($_DDATA['hostname'], $_DDATA['username'], $_DDATA['password']))
	if (mysql_select_db($_DDATA['database'], $_DDATA['link'])) $_DDATA['online'] = true;

$str = "";
if ($_DDATA['online'] && isset($_GET['code'])) {
	$select = mysql_query("SELECT `captcha` FROM `{$_DDATA['tablename']}_auth` WHERE `code`='".addslashes($_GET['code'])."';", $_DDATA['link']);
	if (mysql_num_rows($select)) $str = mysql_result($select, 0, "captcha");
}
if (!$str) for ($i = 0; $i < 5; $i++) $str .= chr(rand(97, 122));

$w = $size * 8;
$h = $size * 2;
$img = imagecreatetruecolor($w, $h);

$colour1 = imagecolorallocate($img,   0,   0,   0);
$colour2 = imagecolorallocate($img,  51,  51,  51);
$colour3 = imagecolorallocate($img, 102, 102, 102);
$colour4 = imagecolorallocate($img, 153, 153, 153);
$colour5 = imagecolorallocate($img, 204, 204, 204);
$colour6 = imagecolorallocate($img, 255, 255, 255);

switch (mt_rand(1, 4)) {
	case 1: $colour = array($colour6, $colour2, $colour4, $colour3); break;
	case 2: $colour = array($colour6, $colour3, $colour1, $colour2); break;
	case 3: $colour = array($colour5, $colour1, $colour3, $colour4); break;
	case 4: $colour = array($colour6, $colour4, $colour2, $colour5); break;
}

imagefill($img, 1, 1, $colour[1]);

$i = 0;
$pixels = mt_rand(200, 5000);
while ($i++ < $pixels) {
	$w2 = mt_rand(1, $w);
	$h2 = mt_rand(1, $h);
	imageline($img, $w2, $h2, $w2, $h2, $colour[2]);
}

$i = 0;
$lines = mt_rand(5, 20);
while ($i++ < $lines)
	imageline($img, mt_rand(1, $w), mt_rand(1, $h), mt_rand(1, $w), mt_rand(1, $h), $colour[3]);

for ($i = 0, $x = 0; $i < strlen($str); $i++) { 
	$s = mt_rand($size - 2, $size + 2);
	$x += mt_rand($size - 1, $size + 3);
	$y = mt_rand((int)($size * 1.3) - 4, (int)($size * 1.3) + 4);
	imagettftext($img, $s, 0, $x + 3, $y + 2, $colour1, $font, $str[$i]);
	imagettftext($img, $s, 0, $x, $y, $colour[0], $font, $str[$i]);
}

imagepng($img);
imagedestroy($img);

?>
Return current item: Orca Ringmaker