<?php
/*
	Copyright(c) 2010 Shift Tech Inc. All Rights Reserved.
 	http://www.shift-tech.jp/
 */

session_start();
header('Content-Type: image/png');

$IMAGE_SIZE_X = 100;
$IMAGE_SIZE_Y = 30;

$image  = imagecreate($IMAGE_SIZE_X, $IMAGE_SIZE_Y);
$cl1  = imagecolorallocate($image, 244,244,244);
$cl2  = imagecolorallocate($image, 0,0,0);
$cl3 = imagecolorallocate($image, 153,153,153);

$text = "";
$s = "123456789ABCDEFGHIJKLMNPQRSTUVWXYZ";
for($i=0;$i<rand(5,5);$i++) {
	$text .= substr($s,rand(0,strlen($s)-1),1);
}

if (isset($_SESSION['capcheck']) && $_SESSION['capcheck'] != '') {
	$text = $_SESSION['capcheck'];
}

for($i=0; $i<strlen($text) - 2; $i++) {
	imageline($image, rand(0,$IMAGE_SIZE_X - 1),rand(0,$IMAGE_SIZE_Y - 1),rand(0,$IMAGE_SIZE_X - 1),rand(0,$IMAGE_SIZE_Y - 1), $cl3);
}
for ($i = 0; $i < strlen($text); $i++) {
	$x += 10 + rand(0, 9);
	$y  = 8 + rand(-7, 7);
	imagechar($image, rand(10,32), $x, $y, substr($text, $i, 1), $cl2);
}
//$image = imagerotate($image, rand(-3, 3), $cl1);
imagepng($image);
imagedestroy($image);
$_SESSION['captext'] = $text;
?>
