Advertisement
Guest User

getCaptcha

a guest
Oct 6th, 2015
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1.  public function getCaptcha()
  2. {
  3.     $letters = '4783abcdefGKIJKLMNOPQRSTUVWXYZ';
  4.     $caplen = 6;
  5.     $width = 120;
  6.     $height = 20;
  7.     $font = 'ComicSpans.ttf';
  8.     $fontsize = 14;
  9.  
  10.     header('Content-type: image/png');
  11.  
  12.     $im = imagecreatetruecolor($width, $height);
  13.     imagesavealpha($im, true);
  14.     $bg = imagecolorallocatealpha($im, 0, 0, 0, 127);
  15.     imagefill($im, 0, 0, $bg);
  16.  
  17.     putenv('GDFONTPATH=' . realpath('.'));
  18.  
  19.     $captcha = '';
  20.     for ($i = 0; $i < $caplen; $i++) {
  21.         $captcha .= $letters[rand(0, strlen($letters) - 1)];
  22.         $x = ($width - 20) / $caplen * $i + 10;
  23.         $x = rand($x, $x + 4);
  24.         $y = $height - (($height - $fontsize) / 2);
  25.         $curcolor = imagecolorallocate($im, rand(0, 100), rand(0, 100), rand(0, 100));
  26.         $angle = rand(-25, 25);
  27.         imagettftext($im, $fontsize, $angle, $x, $y, $curcolor, $font, $captcha[$i]);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement