<?php
$image = imagecreate(120, 30);
$white = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);//bg colour
$gray  = imagecolorallocate($image, 0xcc, 0xcc, 0xcc);//line colour
$darkgray = imagecolorallocate($image, 0x190, 0x190, 0x190);//colour of the font 
$darkgray2 = imagecolorallocate($image, 0x195, 0x195, 0x195);//colour of the font, should be bit lighter than $darkgray 
srand((double)microtime()*1000000);
for($i = 0; $i < 10; $i++)
{
$x1 = rand(0,30);
$y1 = rand(0,20);
$x2 = rand(0,150);
$y2 = rand(0,60);
imageline($image, $x1, $y1, $x2, $y2 , $gray);  
}
$letters = explode(",", "1,2,3,4,5,6,7,8,9,W,E,T,Y,P,D,G,H,K,X,N,M");
for ($i = 0; $i < 5; $i++)
{
$cnum[$i] = $letters[rand(0,20)];
}
for ($i = 0; $i < 5; $i++)
{
$fnt = rand(5,20);
$x = $x + rand(10 , 20);
$y = rand(1, 10);
$c = ($c == $darkgray2) ? $darkgray : $darkgray2;
imagestring($image, $fnt, $x, $y, $cnum[$i] , $c); 
}
$digit = "$cnum[0]$cnum[1]$cnum[2]$cnum[3]$cnum[4]";
session_start();
$_SESSION['digit'] = strtolower($digit);
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
?>