More Captcha Configuration
Posted: 06 November 2007 06:32 AM   [ Ignore ]  
Lab Assistant
Avatar
RankRank
Total Posts:  157
Joined  01-05-2006

It would be nice to have a possibility to configure the Captcha system more deeply. I think every site has a specially designed registration form or comment sending system, where the layout of the Captcha picture should differ. I mean the colors, size, etc. Personally I had to modify the angle of the generated text to fit it in the picture, because the default setting does not allow to long words to look well. So, I had to hack the code to make this possible, and when I am upgrading to a new version or build, I had to make those changes again.

These are my changes in the \system\core\core.functions.php file:

  /**—————————————————-
  /**  Generate Captcha
  /**—————————————————-*/

      ...

      $font_size   = 16;
     
      $expiration = 60*60*2;  // 2 hours
     
      $img_width   = 140;  // Image width
      $img_height   = 30;  // Image height  


      ...

      /**—————————————————-
      /**  Determine angle and position  
      /**—————————————————-*/
     
      $length   = strlen($word);
      $angle   = ($length >= 6) ? rand(-($length-6), ($length-6)) : 0;
      $x_axis   = rand(6, (360/$length)-16);       
      $y_axis = ($angle >= 0 ) ? rand($img_height, $img_width) : rand(6, $img_height);
     
      /**—————————————————-
      /**  Create image
      /**—————————————————-*/
         
      $im = ImageCreate($img_width, $img_height);
         
      /**—————————————————-
      /**  Assign colors
      /**—————————————————-*/
     
      $bg_color     = ImageColorAllocate($im, 255, 255, 255);
      $border_color   = ImageColorAllocate($im, 153, 102, 102);
      $text_color     = ImageColorAllocate($im, 204, 153, 153);
      $grid_color     = imagecolorallocate($im, 255, 182, 182);
      $shadow_color   = imagecolorallocate($im, 255, 240, 240);

      /**—————————————————-
      /**  Create the rectangle
      /**—————————————————-*/
     
      ImageFilledRectangle($im, 0, 0, $img_width, $img_height, $bg_color);
     
      /**—————————————————-
      /**  Create the spiral pattern
      /**—————————————————-*/
     
      $theta     = 1;
      $thetac     = 6; 
      $radius     = 12
      $circles   = 20
      $points     = 36;

Sorry for pasting it here without CODE styling, but I had to highlight the changes.

Profile
 
 
Posted: 06 November 2007 10:13 AM   [ Ignore ]   [ # 1 ]  
Administrator
Avatar
RankRankRankRankRankRankRank
Total Posts:  11294
Joined  06-03-2002

Hacks are not needed; there is an extension hook here for this very purpose, and even a free Advanced Captcha extension that you can use as a starting point if you wish.

 Signature 
Profile
MSG
 
 
Posted: 06 November 2007 10:32 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  157
Joined  01-05-2006

Thanks, I will take a look.

Profile