23 * @copyright Paul Sohier |
23 * @copyright Paul Sohier |
24 */ |
24 */ |
25 |
25 |
26 class captcha_engine_default extends captcha_base |
26 class captcha_engine_default extends captcha_base |
27 { |
27 { |
28 function make_image() |
28 function make_image() |
29 { |
29 { |
30 $code =& strtoupper($this->get_code()); |
30 $code =& strtoupper($this->get_code()); |
31 |
31 |
32 /** |
32 /** |
33 * The next part is orginnaly written by ted from mastercode.nl and modified for use in Enano. |
33 * The next part is orginnaly written by ted from mastercode.nl and modified for use in Enano. |
34 **/ |
34 **/ |
35 header("content-type:image/png"); |
35 header("content-type:image/png"); |
36 header('Cache-control: no-cache, no-store'); |
36 header('Cache-control: no-cache, no-store'); |
37 $breedte = 320; |
37 $breedte = 320; |
38 $hoogte = 60; |
38 $hoogte = 60; |
39 $img = imagecreatetruecolor($breedte,$hoogte); |
39 $img = imagecreatetruecolor($breedte,$hoogte); |
40 $achtergrond = imagecolorallocate($img, $this->color("bg"), $this->color("bg"), $this->color("bg")); |
40 $achtergrond = imagecolorallocate($img, $this->color("bg"), $this->color("bg"), $this->color("bg")); |
41 |
41 |
42 imagefilledrectangle($img, 0, 0, $breedte-1, $hoogte-1, $achtergrond); |
42 imagefilledrectangle($img, 0, 0, $breedte-1, $hoogte-1, $achtergrond); |
43 for($g = 0;$g < 30; $g++) |
43 for($g = 0;$g < 30; $g++) |
44 { |
44 { |
45 $t = $this->dss_rand(); |
45 $t = $this->dss_rand(); |
46 $t = $t[0]; |
46 $t = $t[0]; |
47 |
47 |
48 $ypos = rand(0,$hoogte); |
48 $ypos = rand(0,$hoogte); |
49 $xpos = rand(0,$breedte); |
49 $xpos = rand(0,$breedte); |
50 |
50 |
51 $kleur = imagecolorallocate($img, $this->color("bgtekst"), $this->color("bgtekst"), $this->color("bgtekst")); |
51 $kleur = imagecolorallocate($img, $this->color("bgtekst"), $this->color("bgtekst"), $this->color("bgtekst")); |
52 |
52 |
53 imagettftext($img, $this->size(), $this->move(), $xpos, $ypos, $kleur, $this->font(), $t); |
53 imagettftext($img, $this->size(), $this->move(), $xpos, $ypos, $kleur, $this->font(), $t); |
54 } |
54 } |
55 $stukje = $breedte / (strlen($code) + 3); |
55 $stukje = $breedte / (strlen($code) + 3); |
56 |
56 |
57 for($j = 0;$j < strlen($code); $j++) |
57 for($j = 0;$j < strlen($code); $j++) |
58 { |
58 { |
59 |
59 |
60 |
60 |
61 $tek = $code[$j]; |
61 $tek = $code[$j]; |
62 $ypos = rand(33,43); |
62 $ypos = rand(33,43); |
63 $xpos = $stukje * ($j+1); |
63 $xpos = $stukje * ($j+1); |
64 |
64 |
65 $kleur2 = imagecolorallocate($img, $this->color("tekst"), $this->color("tekst"), $this->color("tekst")); |
65 $kleur2 = imagecolorallocate($img, $this->color("tekst"), $this->color("tekst"), $this->color("tekst")); |
66 |
66 |
67 imagettftext($img, $this->size(), $this->move(), $xpos, $ypos, $kleur2, $this->font() , $tek); |
67 imagettftext($img, $this->size(), $this->move(), $xpos, $ypos, $kleur2, $this->font() , $tek); |
68 } |
68 } |
69 |
69 |
70 imagepng($img); |
70 imagepng($img); |
71 } |
71 } |
72 |
72 |
73 /** |
73 /** |
74 * Some functions :) |
74 * Some functions :) |
75 * Also orginally written by mastercode.nl |
75 * Also orginally written by mastercode.nl |
76 **/ |
76 **/ |
77 /** |
77 /** |
78 * Function to create a random color |
78 * Function to create a random color |
79 * @param $type string Mode for the color |
79 * @param $type string Mode for the color |
80 * @return int |
80 * @return int |
81 **/ |
81 **/ |
82 function color($type) |
82 function color($type) |
83 { |
83 { |
84 switch($type) |
84 switch($type) |
85 { |
85 { |
86 case "bg": |
86 case "bg": |
87 $kleur = rand(224,255); |
87 $kleur = rand(224,255); |
88 break; |
88 break; |
89 case "tekst": |
89 case "tekst": |
90 $kleur = rand(0,127); |
90 $kleur = rand(0,127); |
91 break; |
91 break; |
92 case "bgtekst": |
92 case "bgtekst": |
93 $kleur = rand(200,224); |
93 $kleur = rand(200,224); |
94 break; |
94 break; |
95 default: |
95 default: |
96 $kleur = rand(0,255); |
96 $kleur = rand(0,255); |
97 break; |
97 break; |
98 } |
98 } |
99 return $kleur; |
99 return $kleur; |
100 } |
100 } |
101 /** |
101 /** |
102 * Function to ranom the size |
102 * Function to ranom the size |
103 * @return int |
103 * @return int |
104 **/ |
104 **/ |
105 function size() |
105 function size() |
106 { |
106 { |
107 $grootte = rand(14,30); |
107 $grootte = rand(14,30); |
108 return $grootte; |
108 return $grootte; |
109 } |
109 } |
110 /** |
110 /** |
111 * Function to random the posistion |
111 * Function to random the posistion |
112 * @return int |
112 * @return int |
113 **/ |
113 **/ |
114 function move() |
114 function move() |
115 { |
115 { |
116 $draai = rand(-25,25); |
116 $draai = rand(-25,25); |
117 return $draai; |
117 return $draai; |
118 } |
118 } |
119 |
119 |
120 /** |
120 /** |
121 * Function to return a ttf file from fonts map |
121 * Function to return a ttf file from fonts map |
122 * @return string |
122 * @return string |
123 **/ |
123 **/ |
124 function font() |
124 function font() |
125 { |
125 { |
126 $f = @opendir(ENANO_ROOT . '/includes/captcha/fonts/'); |
126 $f = @opendir(ENANO_ROOT . '/includes/captcha/fonts/'); |
127 if(!$f) die('Can\'t open includes/captcha/fonts/ for reading'); |
127 if(!$f) die('Can\'t open includes/captcha/fonts/ for reading'); |
128 $ar = array(); |
128 $ar = array(); |
129 while(($file = @readdir($f)) !== false) |
129 while(($file = @readdir($f)) !== false) |
130 { |
130 { |
131 if(!in_array($file, array('.','..')) && strstr($file, '.ttf')) |
131 if(!in_array($file, array('.','..')) && strstr($file, '.ttf')) |
132 { |
132 { |
133 $ar[] = $file; |
133 $ar[] = $file; |
134 } |
134 } |
135 } |
135 } |
136 if(count($ar)) |
136 if(count($ar)) |
137 { |
137 { |
138 shuffle($ar); |
138 shuffle($ar); |
139 $i = rand(0,(count($ar) - 1)); |
139 $i = rand(0,(count($ar) - 1)); |
140 return ENANO_ROOT . '/includes/captcha/fonts/' . $ar[$i]; |
140 return ENANO_ROOT . '/includes/captcha/fonts/' . $ar[$i]; |
141 } |
141 } |
142 } |
142 } |
143 function dss_rand() |
143 function dss_rand() |
144 { |
144 { |
145 $val = microtime() . mt_rand(); |
145 $val = microtime() . mt_rand(); |
146 $val = md5($val . 'a'); |
146 $val = md5($val . 'a'); |
147 return substr($val, 4, 16); |
147 return substr($val, 4, 16); |
148 } |
148 } |
149 } |
149 } |