Gazelle/sections/captcha/index.php

55 lines
1.5 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
2013-05-06 08:00:32 +00:00
if (!function_exists('imagettftext')) {
die('Captcha requires both the GD library and the FreeType library.');
}
2011-03-28 14:21:28 +00:00
function get_font() {
global $CaptchaFonts;
return SERVER_ROOT.'/classes/fonts/'.$CaptchaFonts[mt_rand(0,count($CaptchaFonts)-1)];
}
function make_captcha_img() {
global $CaptchaBGs;
2013-02-22 08:00:24 +00:00
2013-05-06 08:00:32 +00:00
$Length = 6;
$ImageHeight = 75;
$ImageWidth = 300;
2013-02-22 08:00:24 +00:00
2013-05-06 08:00:32 +00:00
$Chars = 'abcdefghjkmprstuvwxyzABCDEFGHJKLMPQRSTUVWXY23456789';
$CaptchaString = '';
2013-02-22 08:00:24 +00:00
2013-05-06 08:00:32 +00:00
for ($i = 0; $i < $Length; $i++) {
$CaptchaString.=$Chars[mt_rand(0,strlen($Chars) - 1)];
}
2013-02-22 08:00:24 +00:00
2013-05-06 08:00:32 +00:00
for ($x = 0; $x < $Length; $x++) {
$FontDisplay[$x]['size'] = mt_rand(24,32);
$FontDisplay[$x]['top'] = mt_rand($FontDisplay[$x]['size'] + 5,$ImageHeight - ($FontDisplay[$x]['size'] / 2));
$FontDisplay[$x]['angle'] = mt_rand(-30,30);
$FontDisplay[$x]['font'] = get_font();
2011-03-28 14:21:28 +00:00
}
2013-02-22 08:00:24 +00:00
2013-05-06 08:00:32 +00:00
$Img = imagecreatetruecolor($ImageWidth,$ImageHeight);
$BGImg = imagecreatefrompng(SERVER_ROOT.'/captcha/'.$CaptchaBGs[mt_rand(0,count($CaptchaBGs) - 1)]);
2011-03-28 14:21:28 +00:00
imagecopymerge($Img,$BGImg,0,0,0,0,300,75,50);
2013-05-06 08:00:32 +00:00
$ForeColor = imagecolorallocatealpha($Img,255,255,255,65);
2013-02-22 08:00:24 +00:00
2013-05-06 08:00:32 +00:00
for ($i = 0; $i < strlen($CaptchaString); $i++) {
$CharX = (($ImageWidth / $Length) * ($i + 1)) - (($ImageWidth / $Length) * 0.75);
2011-03-28 14:21:28 +00:00
imagettftext($Img,$FontDisplay[$i]['size'],$FontDisplay[$i]['angle'],$CharX,
$FontDisplay[$i]['top'],$ForeColor,
$FontDisplay[$i]['font'],$CaptchaString[$i]
);
}
header('Content-type: image/png');
imagepng($Img);
imagedestroy($Img);
2013-02-22 08:00:24 +00:00
2011-03-28 14:21:28 +00:00
return $CaptchaString;
}
2013-05-06 08:00:32 +00:00
$_SESSION['captcha'] = make_captcha_img();
?>