PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/quicky/classes/plugins/Captcha/Captcha_draw.class.php

https://bitbucket.org/seyar/startech.local
PHP | 103 lines | 82 code | 6 blank | 15 comment | 9 complexity | 2857d972b461366907ea7d6b74429c2f MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. /**************************************************************************/
  3. /* (c)oded 2006 by white phoenix
  4. /* http://whitephoenix.ru
  5. /*
  6. /* CAPTCHA_draw.class.php
  7. /**************************************************************************/
  8. class CAPTCHA_draw {
  9. public $text;
  10. public $heigth = 33;
  11. public $width = 116;
  12. public $quantity;
  13. public $linecount = 1;
  14. public $linecolor = 0xC6C6C6;
  15. public $textcolor = 0xC6C6C6;
  16. public $bgcolor = 0xA1A1A1;
  17. public $noise1 = FALSE;
  18. public $noise2 = FALSE;
  19. public $noise3 = FALSE;
  20. public $noise_wave_n = 0;
  21. public $noise_skew_n = 1;
  22. public $fonts_dir;
  23. function __construct() {
  24. $this->fonts_dir = dirname(__FILE__).'/fonts/';
  25. }
  26. function generate_text() {
  27. return $this->text = chr_gen('ABCDEFGHKLMNPQRSTUVWXYZ23456789abcdefghkmnpqrstuvwxyz23456789', 5);
  28. }
  29. function show() {
  30. require_once dirname(__FILE__).'/imagedraw.class.php';
  31. ob_start();
  32. $text = $this->text;
  33. $draw = new imagedraw;
  34. $draw->type = 'png';
  35. $draw->W = $this->width;
  36. $draw->H = $this->heigth;
  37. $draw->init();
  38. $draw->createtruecolor();
  39. $draw->antialias(TRUE);
  40. $draw->setbgcolor($this->bgcolor);
  41. //$draw->colortransparent(0xFFFFFF);
  42. $fonts = array();
  43. $fonts = array(
  44. 'Verdana',
  45. 'Times',
  46. 'Tempsitc',
  47. );
  48. // draw text
  49. for($i=0;$i<strlen($text);$i++) {
  50. $size = rand(15,20);
  51. $angle = rand(-10,10);
  52. $x = 10+rand(-5,5)+$i*20;
  53. $y = 20+rand(-5,5)+$size/5;
  54. $font = $fonts[array_rand($fonts)].'.ttf';
  55. $font_p = $this->fonts_dir.$font;
  56. $draw->ttftext($text{$i}, $this->textcolor, $font_p, $size, $x, $y, $angle);
  57. }
  58. // draw line
  59. for ($j = 0; $j < $this->linecount; $j++) {
  60. $lastX = -1;
  61. $lastY = -1;
  62. $N = rand(5, 15);
  63. for ($i = 1; $i < $draw->W+1; $i+=5) {
  64. $X = $i;
  65. $Y = $draw->H/2-sin($X/$N)*10+$j*10;
  66. if ($lastX > -1) {
  67. $draw->line1($lastX,$lastY,$X,$Y,$this->textcolor,2);
  68. }
  69. $lastX = $X;
  70. $lastY = $Y;
  71. }
  72. }
  73. // for ($i = 0; $i < $this->noise_skew_n; $i++) {
  74. // $draw->skew_waves();
  75. // }
  76. //
  77. // $draw->colortransparent(0x000000);
  78. // $draw->setbgcolor($this->bgcolor);
  79. if (strlen(ob_get_contents()) == 0) {
  80. header('Content-type: image/png');
  81. }
  82. $draw->out();
  83. }
  84. }
  85. if (!function_exists('chr_gen')) {
  86. function chr_gen($chars,$len) {
  87. if (!strlen($chars) or !is_numeric($len)) {
  88. return FALSE;
  89. }
  90. $result = '';
  91. $l = strlen($chars)-1;
  92. for($i = 0; $i < $len; $i++) {
  93. $result .= $chars{mt_rand(0,$l)};
  94. }
  95. return $result;
  96. }
  97. }