|
<?php
define('ROOT', '');
$gen = "0123456789";
$gens = strlen($gen);
for($i=0;$i<4;$i++){
$captcha .= $gen{mt_rand(0,$gens-1)};
}
session_start();
$_SESSION['captcha']=$captcha;
header("Content-Type:image/png");
$img_arr = array("1.png");
$font_arr = array();
$font_arr[0]["fname"] = ROOT."CARTOON8.TTF";
$font_arr[0]["size"] = 20;
$n = rand(0,sizeof($font_arr)-1);
$img_fn = $img_arr[rand(0, sizeof($img_arr)-1)];
$im = imagecreatefrompng (ROOT . $img_fn);
$color = imagecolorallocate($im, rand(0, 200), 0, rand(0, 200));
$x = -8;
for($i = 0; $i < strlen($captcha); $i++) {
$x+=15;
$letter=substr($captcha, $i, 1);
imagettftext ($im, 20, rand(2, 4), $x, 23, $color, ROOT.$font_arr[$n]["fname"], $letter);
}
ImagePNG ($im);
ImageDestroy ($im);
?>