' . $img_dir . '0' . $img_type . ' not found!');
$td_width = 10+($img_char_w * $code_max_digits);
for($i=0; $i<$code_max_digits;$i++)
$noautomationcode = $noautomationcode.rand(0,9);
$_SESSION["noautamationdir"] = $img_dir;
$_SESSION["noautamationname"] = $img_name;
srand((double)microtime()*1000000);
// -> OSC-62: Migration vers serveur dédié
// Correction d'un bug du non-affichage du Captcha de la zone d'identification administratrice du site.
// Des variables non initialisées posaient problèmes sur le nouveau serveur VPS, elles ont étés retirées
$img_tmp = "" . rand(1000,999999);
$img_name = $img_tmp;
// <- OSC-62: Migration vers serveur dédié
$_SESSION['image_random_value'] = md5($noautomationcode);
$TheImage = CodeImage($noautomationcode,$img_char_w,$img_char_h,$img_dir,$img_type,$img_dist_level,$img_dist_type);
// send several headers to make sure the image is not cached
// taken directly from the PHP Manual
// Date in the past
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
// send the content type header so the image is displayed properly
header('Content-type: image/jpeg');
ImageJpeg($TheImage);
ImageDestroy($TheImage);
$_SESSION["noautamationcode"] = $noautomationcode;
function CodeImage($code,$img_char_w,$img_char_h,$img_dir,$img_type,$img_dist_level,$img_dist_type){
$length = strlen(trim($code));
clearstatcache();
$img = ImageCreate($img_char_w * $length, $img_char_h);
for($i=0;$i<$length;$i++){
$chr = substr($code,$i,1);
$img_file_path = "$img_dir/$chr$img_type";
if( file_exists($img_file_path) ){
$img_char = ImageCreateFromJpeg($img_file_path) or die("
Image #$i/$chr not created
");
DistortImage($img_char, $img_char_w, $img_char_h,$img_dist_level,$img_dist_type);
//
// On some servers this function works on some others (like Tripod) it doesn't
ImageCopy ($img, $img_char,$i*$img_char_w, 0, 0, 0, $img_char_w, $img_char_h) or die("
Image #$i/$chr not copied
");
ImageDestroy($img_char);
} else {
die("error:>$img_file_path< not found
");
}
}
return $img;
}
function DistortImage($dist_img, $w, $h, $level, $type){
if ($type>3) {
for($i=0;$i<$level;$i++){
$color = ImageColorAllocate($dist_img, rand(0,255), rand(0,255), rand(0,255));
ImageArc($dist_img, rand(0, $w ), rand(0, $h ), rand($w / 2, $w) ,rand($h / 2, $h), 0,360, $color);
}
}
if (($type==2)||($type==3)||($type==6)||($type==7)) {
for($i=0;$i<$level;$i++){
$color = ImageColorAllocate($dist_img, rand(0,255), rand(0,255), rand(0,255));
ImageRectangle($dist_img, rand(0, $w/2 ), rand(0, $h/2 ), rand($w / 2, $w) ,rand($h / 2, $h), $color);
}
}
if (($type==1)||($type==3)||($type==5)||($type==7)) {
$cnt = $w * $h / (11-$level);
for($i=0;$i<$cnt;$i++){
$color = ImageColorAllocate($dist_img, rand(0,255), rand(0,255), rand(0,255));
ImageSetPixel($dist_img, rand(0,$w), rand(0,$h), $color);
}
}
return $dist_img;
}
?>