Changeset 3031 for trunk/system/libraries/drivers/Captcha/Alpha.php
- Timestamp:
- 07/10/2008 11:06:23 AM (5 months ago)
- Files:
-
- 1 modified
-
trunk/system/libraries/drivers/Captcha/Alpha.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/libraries/drivers/Captcha/Alpha.php
r3030 r3031 1 1 <?php defined('SYSPATH') or die('No direct script access.'); 2 2 /** 3 * Captcha driver for " basic" style.3 * Captcha driver for "alpha" style. 4 4 * 5 5 * $Id$ … … 39 39 $this->image_gradient($color1, $color2); 40 40 41 // Add a few random circles 42 for ($i = 0, $count = mt_rand(10, Captcha::$config['complexity'] * 3); $i < $count; $i++) 43 { 44 $color = imagecolorallocatealpha($this->image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255), mt_rand(80, 120)); 45 $size = mt_rand(5, Captcha::$config['height'] / 3); 46 imagefilledellipse($this->image, mt_rand(0, Captcha::$config['width']), mt_rand(0, Captcha::$config['height']), $size, $size, $color); 47 } 48 41 49 // Calculate character font-size and spacing 42 $default_size = min(Captcha::$config['width'], Captcha::$config['height'] * 2) / strlen(Captcha::$ answer);43 $spacing = (int) (Captcha::$config['width'] * 0.9 / strlen(Captcha::$ answer));50 $default_size = min(Captcha::$config['width'], Captcha::$config['height'] * 2) / strlen(Captcha::$response); 51 $spacing = (int) (Captcha::$config['width'] * 0.9 / strlen(Captcha::$response)); 44 52 45 53 // Background alphabetic character attributes … … 48 56 49 57 // Draw each Captcha character with varying attributes 50 for ($i = 0, $strlen = strlen(Captcha::$ answer); $i < $strlen; $i++)58 for ($i = 0, $strlen = strlen(Captcha::$response); $i < $strlen; $i++) 51 59 { 52 60 $angle = mt_rand(-40, 20); 53 61 // Scale the character size on image height 54 62 $size = $default_size / 10 * mt_rand(8, 12); 55 $box = imageftbbox($size, $angle, Captcha::$config['font'], Captcha::$ answer[$i]);63 $box = imageftbbox($size, $angle, Captcha::$config['font'], Captcha::$response[$i]); 56 64 57 65 // Calculate character starting coordinates … … 64 72 65 73 // Write text character to image 66 imagefttext($this->image, $size, $angle, $x, $y, $color, Captcha::$config['font'], Captcha::$ answer[$i]);74 imagefttext($this->image, $size, $angle, $x, $y, $color, Captcha::$config['font'], Captcha::$response[$i]); 67 75 68 76 // Draw "ghost" alphabetic character 69 $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(60, 120)); 70 $char = substr($chars, mt_rand(0,14), 1); 71 imagettftext($this->image, $size, ($angle + (mt_rand(5,10))), ($x - (mt_rand(5,10))), ($y + (mt_rand(5,10))), $text_color, Captcha::$config['font'], $char); 72 77 $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)); 78 $char = substr($chars, mt_rand(0, 14), 1); 79 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); 73 80 } 74 81
