Changeset 3076

Show
Ignore:
Timestamp:
07/11/2008 12:53:22 PM (5 months ago)
Author:
Geert
Message:

Captcha fixes:

  • When using a background image, we shouldn't add an opaque gradient over it, of course.
  • The size of the background image does not overrule the width and height settings anymore. Instead it will be resized if needed to fit right into the given dimension.
Location:
trunk/system/libraries/drivers
Files:
3 modified

Legend:

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

    r3064 r3076  
    7676        public function image_create($background = NULL) 
    7777        { 
    78                 // Use background image 
     78                // Create a new image (black) 
     79                $this->image = imagecreatetruecolor(Captcha::$config['width'], Captcha::$config['height']); 
     80 
     81                // Use a background image 
    7982                if ( ! empty($background)) 
    8083                { 
    81                         $this->image = $this->image_create_from($background); 
     84                        $this->background_image = $this->image_create_from($background); 
    8285 
    83                         // Overwrite the dimensions 
    84                         Captcha::$config['width']  = imagesx($this->image); 
    85                         Captcha::$config['height'] = imagesy($this->image); 
    86                 } 
    87                 // Default background (black) 
    88                 else 
    89                 { 
    90                         $this->image = imagecreatetruecolor(Captcha::$config['width'], Captcha::$config['height']); 
     86                        // Resize the image if needed 
     87                        if (imagesx($this->background_image) !== Captcha::$config['width'] 
     88                            OR imagesy($this->background_image) !== Captcha::$config['height']) 
     89                        { 
     90                                imagecopyresampled 
     91                                ( 
     92                                        $this->image, $this->background_image, 0, 0, 0, 0, 
     93                                        Captcha::$config['width'], Captcha::$config['height'], 
     94                                        imagesx($this->background_image), imagesy($this->background_image) 
     95                                ); 
     96                        } 
     97 
     98                        // Free up resources 
     99                        imagedestroy($this->background_image); 
    91100                } 
    92101        } 
  • trunk/system/libraries/drivers/Captcha/Alpha.php

    r3031 r3076  
    3535 
    3636                // Add a random gradient 
    37                 $color1 = imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); 
    38                 $color2 = imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); 
    39                 $this->image_gradient($color1, $color2); 
     37                if (empty(Captcha::$config['background'])) 
     38                { 
     39                        $color1 = imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); 
     40                        $color2 = imagecolorallocate($this->image, mt_rand(0, 100), mt_rand(0, 100), mt_rand(0, 100)); 
     41                        $this->image_gradient($color1, $color2); 
     42                } 
    4043 
    4144                // Add a few random circles 
  • trunk/system/libraries/drivers/Captcha/Basic.php

    r3032 r3076  
    3535 
    3636                // Add a random gradient 
    37                 $color1 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255)); 
    38                 $color2 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(200, 255)); 
    39                 $this->image_gradient($color1, $color2); 
     37                if (empty(Captcha::$config['background'])) 
     38                { 
     39                        $color1 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255)); 
     40                        $color2 = imagecolorallocate($this->image, mt_rand(200, 255), mt_rand(200, 255), mt_rand(150, 255)); 
     41                        $this->image_gradient($color1, $color2); 
     42                } 
    4043 
    4144                // Add a few random lines