[PHP] Security Image

Well, I was makign a contact form and decided to make a security image so only humans can post, help get rid of the bots. For fonts I created 3 different types and ti loads a random font each time.

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

//Font Stuff------------------------------------------------------------

$server_path = $_SERVER["DOCUMENT_ROOT"];
$folder = "/contact/fonts/";
$path = $server_path.$folder;

$dir = opendir($path);
$number_of_fonts = 0;

while ( $file = readdir($dir) ) {
    if ($file != '.' && $file != '..') {
      $number_of_fonts ++;  
    }
}
//End Of Font Stuff---------------------------------------------------

$chars = "abcdefghijkmnopqrstuvwxyz023456789";
		srand((double)microtime()*1000000);
		$i = 0;
		$hash = '' ;

		while ($i <= 4) {
			$num = rand() % 33;
			$tmp = substr($chars, $num, 1);
			$hash = $hash . $tmp;
			$i++;
		}

$text = $hash;
setcookie("code", $text);
$font  = 10;
$im = @imagecreate (100,30);
$background_color = imagecolorallocate ($im, 0, 0, 0); 
$text_color = imagecolorallocate ($im, 255, 255, 255);//black text
$hm = imagecolorallocate ($im, 32, 178, 170);
$hmone = imagecolorallocate ($im, 255, 140, 0);

for( $i=0; $i < 30; $i++ ) {
    imagefilledellipse ($im, mt_rand(0,100), mt_rand(0,30), mt_rand(0,15), mt_rand(0,15), $hmone);
}

for( $i=0; $i < 300; $i++ ) {
  imagedashedline($im, mt_rand(0,100), mt_rand(0,30), mt_rand(0,100), mt_rand(0,30), $hm);
}

imagefilter($im, IMG_FILTER_SMOOTH, 4);
$fontnum = rand(1,$number_of_fonts);
$ending = ".gdf";
$font = imageloadfont($path.$fontnum.$ending);
imagestring($im, $font, round((100/2)-((strlen($text)*imagefontwidth($font))/2), 1), round((30/2)-(imagefontheight($font)/2)), $text, $text_color);
imagepng ($im);

EXAMPLE : http://files.vanillamints.com/contact/image.php