Changeset 3102
- Timestamp:
- 07/13/2008 05:26:17 AM (5 months ago)
- Location:
- trunk/system
- Files:
-
- 5 modified
-
config/captcha.php (modified) (2 diffs)
-
libraries/Captcha.php (modified) (2 diffs)
-
libraries/drivers/Captcha/Alpha.php (modified) (2 diffs)
-
libraries/drivers/Captcha/Basic.php (modified) (3 diffs)
-
libraries/drivers/Captcha/Black.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/config/captcha.php
r3080 r3102 13 13 * complexity - Difficulty level (0-10), usage depends on chosen style 14 14 * background - Path to background image file 15 * font - Path to font file 15 * fontpath - Path to font folder 16 * fonts - Font files 16 17 * promote - Valid response count threshold to promote user (FALSE to disable) 17 18 */ … … 23 24 'complexity' => 4, 24 25 'background' => '', 25 'font' => SYSPATH.'fonts/DejaVuSerif.ttf', 26 'fontpath' => SYSPATH.'fonts/', 27 'fonts' => array('DejaVuSerif.ttf'), 26 28 'promote' => FALSE, 27 29 ); -
trunk/system/libraries/Captcha.php
r3101 r3102 26 26 'complexity' => 4, 27 27 'background' => '', 28 'font' => '', 28 'fontpath' => '', 29 'fonts' => array(), 29 30 'promote' => FALSE, 30 31 ); … … 109 110 } 110 111 111 // If using a font, check if it exists 112 if ( ! empty($config['font'])) 113 { 114 self::$config['font'] = str_replace('\\', '/', realpath($config['font'])); 115 116 if ( ! file_exists(self::$config['font'])) 117 throw new Kohana_Exception('captcha.file_not_found', self::$config['font']); 112 // If using any fonts, check if they exist 113 if ( ! empty($config['fonts'])) 114 { 115 if (count($config['fonts']) === 1) 116 { 117 if ( ! file_exists(self::$config['fontpath'].self::$config['fonts'][0])) 118 throw new Kohana_Exception('captcha.file_not_found', self::$config['fontpath'].self::$config['fonts'][0]); 119 } 120 else 121 { 122 for ($i = 0; $i < count($config['fonts']); $i++) 123 { 124 if ( ! file_exists(self::$config['fontpath'].self::$config['fonts'][$i])) 125 throw new Kohana_Exception('captcha.file_not_found', self::$config['fontpath'].self::$config['fonts'][$i]); 126 } 127 } 118 128 } 119 129 -
trunk/system/libraries/drivers/Captcha/Alpha.php
r3096 r3102 61 61 for ($i = 0, $strlen = strlen($this->response); $i < $strlen; $i++) 62 62 { 63 // Use different fonts if available 64 $font = Captcha::$config['fontpath'].Captcha::$config['fonts'][(mt_rand(0, (count(Captcha::$config['fonts']) - 1)))]; 65 63 66 $angle = mt_rand(-40, 20); 64 67 // Scale the character size on image height 65 68 $size = $default_size / 10 * mt_rand(8, 12); 66 $box = imageftbbox($size, $angle, Captcha::$config['font'], $this->response[$i]);69 $box = imageftbbox($size, $angle, $font, $this->response[$i]); 67 70 68 71 // Calculate character starting coordinates … … 75 78 76 79 // Write text character to image 77 imagefttext($this->image, $size, $angle, $x, $y, $color, Captcha::$config['font'], $this->response[$i]);80 imagefttext($this->image, $size, $angle, $x, $y, $color, $font, $this->response[$i]); 78 81 79 82 // Draw "ghost" alphabetic character 80 83 $text_color = imagecolorallocatealpha($this->image, mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand(70, 120)); 81 84 $char = substr($chars, mt_rand(0, 14), 1); 82 imagettftext($this->image, $size * 2, mt_rand(-45, 45), ($x - (mt_rand(5, 10))), ($y + (mt_rand(5, 10))), $text_color, Captcha::$config['font'], $char);85 imagettftext($this->image, $size * 2, mt_rand(-45, 45), ($x - (mt_rand(5, 10))), ($y + (mt_rand(5, 10))), $text_color, $font, $char); 83 86 } 84 87 -
trunk/system/libraries/drivers/Captcha/Basic.php
r3096 r3102 56 56 for ($i = 0, $strlen = strlen($this->response); $i < $strlen; $i++) 57 57 { 58 // Use different fonts if available 59 $font = Captcha::$config['fontpath'].Captcha::$config['fonts'][(mt_rand(0, (count(Captcha::$config['fonts']) - 1)))]; 60 58 61 // Allocate random color, size and rotation attributes to text 59 62 $color = imagecolorallocate($this->image, mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 150)); … … 62 65 // Scale the character size on image height 63 66 $size = $default_size / 10 * mt_rand(8, 12); 64 $box = imageftbbox($size, $angle, Captcha::$config['font'], $this->response[$i]);67 $box = imageftbbox($size, $angle, $font, $this->response[$i]); 65 68 66 69 // Calculate character starting coordinates … … 69 72 70 73 // Write text character to image 71 imagefttext($this->image, $size, $angle, $x, $y, $color, Captcha::$config['font'], $this->response[$i]);74 imagefttext($this->image, $size, $angle, $x, $y, $color, $font, $this->response[$i]); 72 75 } 73 76 -
trunk/system/libraries/drivers/Captcha/Black.php
r3097 r3102 44 44 } 45 45 46 // Use different fonts if available 47 $font = Captcha::$config['fontpath'].Captcha::$config['fonts'][(mt_rand(0, (count(Captcha::$config['fonts']) - 1)))]; 48 46 49 // Draw the character's white shadows 47 50 $size = (int) min(Captcha::$config['height'] / 2, Captcha::$config['width'] * 0.8 / strlen($this->response)); … … 50 53 $y = ((Captcha::$config['height'] - $size) / 2) + $size; 51 54 $color = imagecolorallocate($this->image, 255, 255, 255); 52 imagefttext($this->image, $size, $angle, $x + 1, $y + 1, $color, Captcha::$config['font'], $this->response);55 imagefttext($this->image, $size, $angle, $x + 1, $y + 1, $color, $font, $this->response); 53 56 54 57 // Add more shadows for lower complexities 55 (Captcha::$config['complexity'] < 10) and imagefttext($this->image, $size, $angle, $x - 1, $y - 1, $color, Captcha::$config['font'], $this->response);56 (Captcha::$config['complexity'] < 8) and imagefttext($this->image, $size, $angle, $x - 2, $y + 2, $color, Captcha::$config['font'], $this->response);57 (Captcha::$config['complexity'] < 6) and imagefttext($this->image, $size, $angle, $x + 2, $y - 2, $color, Captcha::$config['font'], $this->response);58 (Captcha::$config['complexity'] < 4) and imagefttext($this->image, $size, $angle, $x + 3, $y + 3, $color, Captcha::$config['font'], $this->response);59 (Captcha::$config['complexity'] < 2) and imagefttext($this->image, $size, $angle, $x - 3, $y - 3, $color, Captcha::$config['font'], $this->response);58 (Captcha::$config['complexity'] < 10) and imagefttext($this->image, $size, $angle, $x - 1, $y - 1, $color, $font , $this->response); 59 (Captcha::$config['complexity'] < 8) and imagefttext($this->image, $size, $angle, $x - 2, $y + 2, $color, $font , $this->response); 60 (Captcha::$config['complexity'] < 6) and imagefttext($this->image, $size, $angle, $x + 2, $y - 2, $color, $font , $this->response); 61 (Captcha::$config['complexity'] < 4) and imagefttext($this->image, $size, $angle, $x + 3, $y + 3, $color, $font , $this->response); 62 (Captcha::$config['complexity'] < 2) and imagefttext($this->image, $size, $angle, $x - 3, $y - 3, $color, $font , $this->response); 60 63 61 64 // Finally draw the foreground characters 62 65 $color = imagecolorallocate($this->image, 0, 0, 0); 63 imagefttext($this->image, $size, $angle, $x, $y, $color, Captcha::$config['font'], $this->response);66 imagefttext($this->image, $size, $angle, $x, $y, $color, $font, $this->response); 64 67 65 68 // Output
