33
44/**
55 *
6- * Require Image_Text class for generating the text.
6+ * Require ImageText class for generating the text.
77 *
88 */
99require_once 'CAPTCHA.php ' ;
1212/**
1313 * Text_CAPTCHA_Driver_Image - Text_CAPTCHA driver graphical CAPTCHAs
1414 *
15- * Class to create a graphical Turing test
15+ * Class to create a graphical Turing test
16+ *
1617 *
17- *
1818 * @license BSD License
1919 * @author Christian Wenz <wenz@php.net>
2020 * @todo refine the obfuscation algorithm :-)
21- * @todo consider removing Image_Text dependency
21+ * @todo consider removing ImageText dependency
2222 */
2323
2424class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA
@@ -33,7 +33,7 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA
3333 public $ _im ;
3434
3535 /**
36- * Image_Text object
36+ * ImageText object
3737 *
3838 * @access private
3939 * @public resource
@@ -59,7 +59,7 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA
5959 /**
6060 * Phrase length of CAPTCHA
6161 *
62- * @access public static
62+ * @access public static
6363 * @public int
6464 */
6565 public static $ _phraseLength ;
@@ -73,7 +73,7 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA
7373 public $ _output ;
7474
7575 /**
76- * Further options (here: for Image_Text )
76+ * Further options (here: for ImageText )
7777 *
7878 * @access private
7979 * @public array
@@ -85,7 +85,7 @@ class Text_CAPTCHA_Driver_Image extends Text_CAPTCHA
8585 'text_color ' => '#000000 ' ,
8686 'lines_color ' => '#CACACA ' ,
8787 'background_color ' => '#555555 ' );
88-
88+
8989 /**
9090 * Whether the immage resource has been created
9191 *
@@ -115,17 +115,17 @@ public function init($options = array())
115115 {
116116 if (!is_array ($ options )) {
117117 // Compatibility mode ... in future versions, these two
118- // lines of code will be used:
118+ // lines of code will be used:
119119 // $this->_error = PEAR::raiseError('You need to provide a set of CAPTCHA options!');
120- // return $this->_error;
120+ // return $this->_error;
121121 $ o = array ();
122122 $ args = func_get_args ();
123123 if (isset ($ args [0 ])) {
124124 $ o ['width ' ] = $ args [0 ];
125- }
125+ }
126126 if (isset ($ args [1 ])) {
127127 $ o ['height ' ] = $ args [1 ];
128- }
128+ }
129129 if (isset ($ args [2 ]) && $ args [2 ] != null ) {
130130 $ o ['phrase ' ] = $ args [2 ];
131131 }
@@ -134,16 +134,16 @@ public function init($options = array())
134134 }
135135 $ options = $ o ;
136136 }
137- if (is_array ($ options )) {
137+ if (is_array ($ options )) {
138138 if (isset ($ options ['width ' ]) && is_int ($ options ['width ' ])) {
139- $ this ->_width = $ options ['width ' ];
139+ $ this ->_width = $ options ['width ' ];
140140 } else {
141- $ this ->_width = 200 ;
141+ $ this ->_width = 200 ;
142142 }
143143 if (isset ($ options ['height ' ]) && is_int ($ options ['height ' ])) {
144- $ this ->_height = $ options ['height ' ];
144+ $ this ->_height = $ options ['height ' ];
145145 } else {
146- $ this ->_height = 80 ;
146+ $ this ->_height = 80 ;
147147 }
148148 if (!isset ($ options ['phrase ' ]) || empty ($ options ['phrase ' ])) {
149149 $ phraseoptions = (isset ($ options ['phraseOptions ' ]) && is_array ($ options ['phraseOptions ' ])) ? $ options ['phraseOptions ' ] : array ();
@@ -155,9 +155,9 @@ public function init($options = array())
155155 $ this ->_output = 'resource ' ;
156156 } else {
157157 $ this ->_output = $ options ['output ' ];
158- }
158+ }
159159 if (isset ($ options ['imageOptions ' ]) && is_array ($ options ['imageOptions ' ]) && count ($ options ['imageOptions ' ]) > 0 ) {
160- $ this ->_imageOptions = array_merge ($ this ->_imageOptions , $ options ['imageOptions ' ]);
160+ $ this ->_imageOptions = array_merge ($ this ->_imageOptions , $ options ['imageOptions ' ]);
161161 }
162162 return true ;
163163 }
@@ -172,11 +172,11 @@ public function init($options = array())
172172 */
173173 public function _createPhrase ($ options = array ())
174174 {
175- if (isset (self ::$ _phraseLength )) {
176- $ len = intval (min (self ::$ _phraseLength , $ this ->_width / 25 ));
177- } else {
178- $ len = intval (min (8 , $ this ->_width / 25 ));
179- }
175+ if (isset (self ::$ _phraseLength )) {
176+ $ len = intval (min (self ::$ _phraseLength , $ this ->_width / 25 ));
177+ } else {
178+ $ len = intval (min (8 , $ this ->_width / 25 ));
179+ }
180180 if (!is_array ($ options ) || count ($ options ) === 0 ) {
181181 $ this ->_phrase = Text_Password::create ($ len );
182182 } else {
@@ -208,11 +208,11 @@ public function _createCAPTCHA()
208208 $ options ['canvas ' ] = array (
209209 'width ' => $ this ->_width ,
210210 'height ' => $ this ->_height
211- );
211+ );
212212 $ options ['width ' ] = $ this ->_width - 20 ;
213- $ options ['height ' ] = $ this ->_height - 20 ;
213+ $ options ['height ' ] = $ this ->_height - 20 ;
214214 $ options ['cx ' ] = ceil (($ this ->_width ) / 2 + 10 );
215- $ options ['cy ' ] = ceil (($ this ->_height ) / 2 + 10 );
215+ $ options ['cy ' ] = ceil (($ this ->_height ) / 2 + 10 );
216216 $ options ['angle ' ] = rand (0 , 30 ) - 15 ;
217217 $ options ['font_size ' ] = $ this ->_imageOptions ['font_size ' ];
218218 $ options ['font_path ' ] = $ this ->_imageOptions ['font_path ' ];
@@ -222,26 +222,29 @@ public function _createCAPTCHA()
222222 $ options ['max_lines ' ] = 1 ;
223223 $ options ['mode ' ] = 'auto ' ;
224224 do {
225- $ this ->_imt = new Image_Text (
225+ $ this ->_imt = new ImageText (
226226 $ this ->_phrase ,
227227 $ options
228228 );
229229 if (PEAR ::isError ($ e = $ this ->_imt ->init ())) {
230230 $ this ->_error = PEAR ::raiseError (
231- sprintf ('Error initializing Image_Text (%s) ' ,
232- $ e ->getMessage ()));
231+ sprintf (
232+ 'Error initializing ImageText (%s) ' ,
233+ $ e ->getMessage ()
234+ )
235+ );
233236 return $ this ->_error ;
234237 } else {
235- $ this ->_created = true ;
238+ $ this ->_created = true ;
236239 }
237240 $ result = $ this ->_imt ->measurize ();
238241 } while ($ result === false && --$ options ['font_size ' ] > 0 );
239242 if ($ result === false ) {
240243 $ this ->_error = PEAR ::raiseError ('The text provided does not fit in the image dimensions ' );
241244 return $ this ->_error ;
242245 }
243- $ this ->_imt ->render ();
244- $ this ->_im =& $ this ->_imt ->getImg ();
246+ $ this ->_imt ->render ();
247+ $ this ->_im =& $ this ->_imt ->getImg ();
245248 $ colors = $ this ->_imt ->_convertString2RGB ($ this ->_imageOptions ['lines_color ' ]);
246249 $ lines_color = imagecolorallocate ($ this ->_im , $ colors ['r ' ], $ colors ['g ' ], $ colors ['b ' ]);
247250 //some obfuscation
@@ -277,7 +280,7 @@ public function getCAPTCHA()
277280 if (PEAR ::isError ($ retval )) {
278281 return PEAR ::raiseError ($ retval ->getMessage ());
279282 }
280-
283+
281284 if ($ this ->_output == 'gif ' && !function_exists ('imagegif ' )) {
282285 $ this ->_output = 'png ' ;
283286 }
@@ -286,7 +289,7 @@ public function getCAPTCHA()
286289 case 'png ' :
287290 return $ this ->getCAPTCHAAsPNG ();
288291 break ;
289- case 'jpg ' :
292+ case 'jpg ' :
290293 case 'jpeg ' :
291294 return $ this ->getCAPTCHAAsJPEG ();
292295 break ;
@@ -386,5 +389,5 @@ public function getCAPTCHAAsGIF()
386389 public function __wakeup ()
387390 {
388391 $ this ->_created = false ;
389- }
392+ }
390393}
0 commit comments