<?php
  session_start();
  $_SESSION['captcha'] = rand(1000,9999);
  
 $img = imagecreatetruecolor(40, 20);
 
 $fill_color=imagecolorallocate($img,255,255,255);
 imagefilledrectangle($img, 0, 0, 40, 20, $fill_color);
 $text_color=imagecolorallocate($img,10,10,10);
 $font = 'fonte.ttf';
 imagettftext($img, 8, 0, 10,15, $text_color, $font, $_SESSION['captcha']);
 
 header("Content-type: image/jpeg");
 imagejpeg($img);
 imagedestroy($img);
?>