<?php
error_reporting(0);
$chars = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
$count = count($chars) - 1;
$key = array();
$i=0;
while ($i<5)
{
$content.=$chars[mt_rand(0, $count)];
$i++;
}
$img_x = 90;
$img_y = 25;
$font = 'font.ttf';
session_start();
$_SESSION['captcha'] = $content;
$img = imagecreate($img_x, $img_y);
$colours = array();
$colours['white'] = imagecolorallocate($img, 255, 255, 255);
$colours['grey'] = imagecolorallocate($img, 230, 230, 230);
$colours['black'] = imagecolorallocate($img, 0, 0, 0);
$number_of_x_lines = ($img_x - 1) / 6;
$number_of_y_lines = ($img_y - 1) / 6;
for($i = 0; $i < $number_of_x_lines; $i++){
imageline($img, $i * $number_of_x_lines, 0, $i * $number_of_x_lines, $img_y, $colours['black']);}
for($i = 0; $i < $number_of_y_lines; $i++){
imageline($img, 0, $i * $number_of_y_lines, $img_x, $i * $number_of_y_lines, $colours['black']);}
$txt_bbox = imagettfbbox(20, 0, $font, $content);
$sx = ($img_x - ($txt_bbox[2] - $txt_bbox[0])) / 2;
$sy = ($img_y - ($txt_bbox[1] - $txt_bbox[7])) / 2;
$sy -= $txt_bbox[7];
header('Content-type: image/png');
imagettftext($img, 15, /*mt_rand(-10, 10)*/0, /*$sx, $sy,*/5, 20, $colours['black'], $font, $content);
imagepng($img);
imagedestroy($img);
//тест
?>