Просмотр файла utils/captcha.php

Размер файла: 1.95Kb
  1. <?php
  2.  
  3. $width = 130; //Ширина изображения
  4. $height = 80; //Высота изображения
  5. $font_size = 16; //Размер шрифта
  6. $let_amount = 4; //Количество символов, которые нужно набрать
  7. $fon_let_amount = 15; //Количество символов, которые находятся на фоне
  8. $path_fonts = '../design/fonts/'; //Путь к шрифтам
  9. $letters = array('0','2','3','4','5','6','7','9');
  10. $colors = array('10','30','50','70','90','110','130','150','170','190','210');
  11. $src = imagecreatetruecolor($width,$height);
  12. $fon = imagecolorallocate($src,255,255,255);
  13.  
  14. imagefill($src, 0, 0, $fon);
  15. $fonts = array();
  16. $dir=opendir($path_fonts);
  17.  
  18. while($fontName = readdir($dir)) {
  19.  
  20. if($fontName != "." && $fontName != "..") {
  21. $fonts[] = $fontName;
  22. }
  23. }
  24.  
  25. closedir($dir);
  26. for($i=0; $i<$fon_let_amount; $i++) {
  27.  
  28. $color = imagecolorallocatealpha($src,rand(0,255),rand(0,255),rand(0,255),100);
  29. $font = $path_fonts.$fonts[rand(0,sizeof($fonts)-1)];
  30. $letter = $letters[rand(0,sizeof($letters)-1)];
  31. $size = rand($font_size-2,$font_size+2);
  32. imagettftext($src, $size, rand(0, 45), rand($width * 0.1, $width - $width * 0.1), rand($height * 0.2, $height), $color, $font, $letter);
  33.  
  34. }
  35. for($i=0; $i<$let_amount; $i++) {
  36.  
  37. $color = imagecolorallocatealpha($src,$colors[rand(0,sizeof($colors)-1)],$colors[rand(0,sizeof($colors)-1)],$colors[rand(0,sizeof($colors)-1)],rand(20,40));
  38. $font = $path_fonts.$fonts[rand(0,sizeof($fonts)-1)];
  39. $letter = $letters[rand(0,sizeof($letters)-1)];
  40. $size = rand($font_size*2.1-2,$font_size*2.1+2);
  41. $x = ($i+1)*$font_size + rand(4,7);
  42. $y = (($height*2)/3) + rand(0,5);
  43. $cod[] = $letter;
  44. imagettftext($src,$size,rand(0,15),$x,$y,$color,$font,$letter);
  45.  
  46. }
  47.  
  48. // запуск сессий
  49. session_name('sid');
  50. session_start();
  51. $_SESSION['code'] = implode('', $cod);
  52. header ("Content-type: image/gif");
  53. imagegif($src);
  54.  
  55. ?>