> 1;
$color[ 'g' ] = ( $lhs[ 'g' ] + $rhs[ 'g' ] ) >> 1;
$color[ 'b' ] = ( $lhs[ 'b' ] + $rhs[ 'b' ] ) >> 1;
return $color;
}
$text = $_SESSION[ 'capcha_' . $_GET[ 'entry' ] ];
srand( ( double ) microtime() * 1000000 );
// Creates a simple image
$image = imagecreate($CONFIG[ 'width' ], $CONFIG[ 'height' ]);
// Create random colors
$rgb = array();
$rgb[ 'background' ] = rgb_rand( 0, 255 );
$rgb[ 'foreground' ] = rgb_grayscale( rgb_complementary( $rgb[ 'background' ] ) );
if ( $rgb[ 'foreground' ][ 'r' ] > 127 ) {
$inicio = -127;
$rgb[ 'foreground' ] = rgb_merge( $rgb[ 'foreground' ], rgb_create( 255, 255, 255 ) );
$rgb[ 'shadow' ] = rgb_merge( rgb_complementary( $rgb[ 'foreground' ] ), rgb_create( 0, 0, 0 ) );
} else {
$inicio = 0;
$rgb[ 'foreground' ] = rgb_merge( $rgb[ 'foreground' ], rgb_create( 0, 0, 0 ) );
$rgb[ 'shadow' ] = rgb_merge( rgb_complementary( $rgb[ 'foreground' ] ), rgb_create( 255, 255, 255 ) );
} // if
// Allocate color resources
$color = array();
foreach($rgb as $name => $value) {
$color[$name] = imagecolorallocate( $image, $value[ 'r' ], $value[ 'g' ], $value[ 'b' ] );
} // foreach
// Draw background
imagefilledrectangle( $image, 0, 0, 120, 30, $color[ 'background' ] );
// Write some random text on background
for ( $i = 0; $i < rand( 5, 9 ); $i++ ) {
$x = rand( 0, $CONFIG[ 'width' ] );
$y = rand( 0, $CONFIG[ 'height' ] );
$f = rand( 0, 5 );
$c = rgb_grayscale( rgb_rand( 127 - $inicio, 254 - $inicio ) );
$color[$i] = imagecolorallocate( $image, $c[ 'r' ], $c[ 'g' ], $c[ 'b' ] );
imagestring( $image, $f, $x, $y, $text, $color[$i] );
}
// Center the real captcha text
$x = ( $CONFIG[ 'width' ] - ( ImageFontWidth($CONFIG[ 'font_id' ] ) * strlen($text) ) ) >> 1;
$y = ( $CONFIG[ 'height' ] - ImageFontHeight($CONFIG[ 'font_id' ] ) ) >> 1;
// Write the captcha text with shadow (improves the human vision in some cases)
imagestring( $image, $CONFIG[ 'font_id' ], $x + 1, $y + 1, $text, $color[ 'shadow' ] );
imagestring( $image, $CONFIG[ 'font_id' ], $x, $y, $text, $color[ 'foreground' ] );
// Returns the image
header( 'Content-type: image/png' );
imagepng( $image );
// Free resources
foreach($color as $name => $value) {
imagecolordeallocate( $image, $value );
} // foreach
imagedestroy( $image );
?>