Show
Ignore:
Timestamp:
05/07/2008 09:24:19 AM (7 months ago)
Author:
OscarB
Message:

Changes to use standard font in system/fonts.
Add new 'alphasoup' captcha style based on Pulstar's forum post.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Captcha.php

    r2547 r2652  
    235235 
    236236        /** 
     237         * Draws the alphasoup Captcha image: 
     238         * Requires GD with freetype and available truetype compatible font files. 
     239         * 
     240         * @param   none 
     241         * @return  void 
     242         */ 
     243        protected function alphasoup_captcha() 
     244        { 
     245                $this->img_create(); 
     246                $font = $this->font_path.$this->font_name; 
     247                $text_color = imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); 
     248                $color_limit = mt_rand(96, 160); 
     249                $fill_color = imageColorAllocate($this->image, mt_rand($color_limit, 255), mt_rand($color_limit, 255), mt_rand($color_limit, 255)); 
     250                imageFilledRectangle($this->image, 0, 0, $this->width, $this->height, $fill_color); 
     251                $font_width = imageFontWidth(10); 
     252                $chars = 'ABCDEFGHIJKLMNO'; 
     253 
     254                for($loop = 0; $loop < 20; $loop++) 
     255                { 
     256                        $text_color = imageColorAllocate($this->image, mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255)); 
     257                        $char = substr($chars, mt_rand(0,15), 1); 
     258                        imageTTFtext($this->image, mt_rand(23, 27), mt_rand(160, 200), mt_rand(-10, $this->width+10), mt_rand(-10, 60), $text_color, $font, $char); 
     259                } 
     260 
     261                $this->calculate_spacing(); 
     262                // Draw each Captcha character with varying attributes 
     263                for ($i = 0, $strlen = strlen($this->captcha_code); $i < $strlen; $i++) 
     264                { 
     265                        // Allocate random color, size and rotation attributes to text 
     266                        $text_color = imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); 
     267                        $angle = mt_rand(-40, 40); 
     268 
     269                        // Make first char angle inward 
     270                        if ($i === 0) 
     271                        { 
     272                                $angle = -abs($angle); 
     273                        } 
     274                        // Make last char angle inward 
     275                        if ($i === ($this->num_chars - 1)) 
     276                        { 
     277                                $angle = abs($angle); 
     278                        } 
     279 
     280                        // Scale the character size on image height 
     281                        $font_size = mt_rand($this->height - 20, $this->height - 12); 
     282                        $char_details = imageftbbox($font_size, $angle, $font, $this->captcha_code[$i], array()); 
     283 
     284                        // Calculate character starting coordinates 
     285                        $iX = $this->spacing / 4 + $i * $this->spacing; 
     286                        $char_height = $char_details[2] - $char_details[5]; 
     287                        $iY = $this->height / 2 + $char_height / 4; 
     288 
     289                        // Write text character to image 
     290                        imagefttext($this->image, $font_size, $angle, $iX, $iY, $text_color, $font, $this->captcha_code[$i], array()); 
     291                } 
     292 
     293        } 
     294 
     295        /** 
    237296         * Draws the math riddle Captcha image. 
    238297         * Requires GD with freetype and available truetype compatible font files.