<?php
# captcha.php
#######################################
# HTTP Viewer Captcha Version © 2012 Scott Connell
# Created: 2012/10/04 (year/month/day)
# License: Free for personal and commercial use.
# Terms: Redistribution/republishing strictly forbidden.
# Source: http://scottconnell.orgfree.com
#######################################
include_once("config.php");
$textkey = $_COOKIE['UID'];
$width = 200;
$height = 60;
$image = ImageCreate($width, $height) or die("Cannot Create image");
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
imagettftext($image, 40, 0, 25, 50, $black, $font_path, $textkey);
$image2 = ImageCreate($width, $height) or die("Cannot Create image");
$grayscale0 = imagecolorallocate($image2, 153, 153, 153);
$grayscale1 = imagecolorallocate($image2, 178, 178, 178);
$grayscale2 = imagecolorallocate($image2, 204, 204, 204);
$grayscale3 = imagecolorallocate($image2, 229, 229, 229);
$grayscale4 = imagecolorallocate($image2, 255, 255, 255);
for($x=0;$x<$width;$x++)
{
for($y=0;$y<$height;$y++)
{
$random = mt_rand(0, 4);
if(!$random)
{
imagesetpixel($image2, $x, $y, $grayscale0);
}
if($random == 1)
{
imagesetpixel($image2, $x, $y, $grayscale1);
}
if($random == 2)
{
imagesetpixel($image2, $x, $y, $grayscale2);
}
if($random == 3)
{
imagesetpixel($image2, $x, $y, $grayscale3);
}
if($random == 4)
{
imagesetpixel($image2, $x, $y, $grayscale4);
}
}
}
imagecopymerge($image, $image2, 0, 0, 0, 0, $width, $height, 60);
$x_period = 10;
$y_period = 10;
$y_amplitude = 5;
$x_amplitude = 5;
$xp = $x_period*rand(1,3);
$k = rand(0,100);
for ($a = 0; $a<$width; $a++)
{
imagecopy($image, $image, $a-1, sin($k+$a/$xp)*$x_amplitude, $a, 0, 1, $height);
}
$yp = $y_period*rand(1,2);
$k = rand(0,100);
for ($a = 0; $a<$height; $a++)
{
imagecopy($image, $image, sin($k+$a/$yp)*$y_amplitude, $a-1, 0, $a, $width, 1);
}
header("Content-type: image/png");
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Wed, 22 Jul 1964 22:00:00 GMT"); // In the past
header("Pragma: no-cache");
imagepng($image);
imagedestroy($image);
imagedestroy($image2);
?>