? translations/nl.po-old
Index: image_captcha/image_captcha.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/image_captcha/image_captcha.admin.inc,v
retrieving revision 1.3
diff -u -u -p -r1.3 image_captcha.admin.inc
--- image_captcha/image_captcha.admin.inc	7 Jan 2008 13:34:53 -0000	1.3
+++ image_captcha/image_captcha.admin.inc	25 Mar 2008 20:13:07 -0000
@@ -86,6 +86,43 @@ function image_captcha_settings_form() {
       '1.5' => t('large'),
     ),
   );
+  
+    // color settings
+  $form['image_captcha_color_settings'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Color settings'),
+    '#description' => t('Configuration of the colors of background and foreground in the image CAPTCHA.'),
+  );
+  $form['image_captcha_color_settings']['image_captcha_background_color'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Background color'),
+    '#description' => t('Enter the hexadecimal code for the background color (e.g. #FFF or #FFCE90).'),
+    '#default_value' => variable_get('image_captcha_background_color', '#ffffff'),
+    '#maxlength' => 7,
+    '#size' => 8,
+  );
+  $form['image_captcha_color_settings']['image_captcha_foreground_color'] = array(
+    '#type' => 'textfield',
+    '#title' => t('Foreground color'),
+    '#description' => t('Enter the hexadecimal code for the foreground color (e.g. #000 or #004283).'),
+    '#default_value' => variable_get('image_captcha_foreground_color', '#000000'),
+    '#maxlength' => 7,
+    '#size' => 8,
+  );
+  $form['image_captcha_color_settings']['image_captcha_foreground_color_randomness'] = array(
+    '#type' => 'select',
+    '#title' => t('Additional variation of foreground color'),
+    '#options' => array(
+      0 => t('none'),
+      50 => t('small'),
+      100 => t('moderate'),
+      150 => t('high'),
+      200 => t('very high'),
+    ),
+    '#default_value' => (int) variable_get('image_captcha_foreground_color_randomness', 100),
+    '#description' => t('The different characters will have randomized colors in the specified range around the foreground color.'),
+  );
+
 
   // distortion and noise settings
   $form['image_captcha_distortion_and_noise'] = array(
@@ -178,4 +215,12 @@ function image_captcha_settings_form_val
   elseif ($font != 'BUILTIN' && (!is_file($font) || !is_readable($font))) {
     form_set_error('image_captcha_font', t('Font does not exist or is not readable.'));
   }
+  
+  // check color settings
+ if (!preg_match('/^#([0-9a-fA-F]{3}){1,2}$/', $form_state['values']['image_captcha_background_color'])){
+  form_set_error('image_captcha_background_color', t('Background color is not a valid hexadecimal color value.'));
+  }
+  if (!preg_match('/^#([0-9a-fA-F]{3}){1,2}$/', $form_state['values']['image_captcha_foreground_color'])){
+    form_set_error('image_captcha_foreground_color', t('Foreground color is not a valid hexadecimal color value.'));
+  }
 }
Index: image_captcha/image_captcha.user.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/image_captcha/image_captcha.user.inc,v
retrieving revision 1.3
diff -u -u -p -r1.3 image_captcha.user.inc
--- image_captcha/image_captcha.user.inc	7 Jan 2008 13:34:53 -0000	1.3
+++ image_captcha/image_captcha.user.inc	25 Mar 2008 20:13:07 -0000
@@ -43,6 +43,24 @@ function image_captcha_image($seed=NULL)
   }
 }
 
+
+/**
+ * small helper function for parsing a hexadecimal color to a RGB tuple
+ */
+function _image_captcha_hex_to_rgb($hex) {
+  // handle #RGB format
+  if (strlen($hex) == 4) {
+    $hex = $hex[1] . $hex[1] . $hex[2] . $hex[2] . $hex[3] . $hex[3];
+  }
+  $c = hexdec($hex);
+  $rgb = array();
+  for ($i = 16; $i >= 0; $i -= 8) {
+    $rgb[] = ($c >> $i) & 0xFF;
+  }
+  return $rgb;
+}
+
+
 /**
  * base function for generating a image CAPTCHA
  */
@@ -67,8 +85,9 @@ function _image_captcha_generate_image($
     return FALSE;
   }
 
-  // background
-  $background_color = imagecolorallocate($image, 255, 255, 255);
+  // get background color and paint
+  $background_rgb = _image_captcha_hex_to_rgb(variable_get('image_captcha_background_color', '#ffffff'));
+  $background_color = imagecolorallocate($image, $background_rgb[0], $background_rgb[1], $background_rgb[2]);
   imagefilledrectangle($image, 0, 0, $width, $height, $background_color);
 
   // draw text
@@ -205,7 +224,12 @@ function _image_captcha_image_generator_
   }
 }
 
-function _image_captcha_image_generator_print_string(&$image, $width, $height, $font, $font_size, $text, $light_colors=FALSE) {
+ /**
+ * Helper function for drawing text on the image
+ * 
+ * @param $background_mode if the text is for the background of the double vision mode
+ */
+function _image_captcha_image_generator_print_string(&$image, $width, $height, $font, $font_size, $text, $background_mode=FALSE) {
   // get characters
   $characters = _image_captcha_utf8_split($text);
   $character_quantity = count($characters);
@@ -227,6 +251,33 @@ function _image_captcha_image_generator_
   // character jittering
   $jittering_x = .3 * $font_size;
   $jittering_y = .3 * $font_size;
+  
+  // get colors
+  $background_rgb = _image_captcha_hex_to_rgb(variable_get('image_captcha_background_color', '#ffffff'));
+  $foreground_rgb = _image_captcha_hex_to_rgb(variable_get('image_captcha_foreground_color', '#000000'));
+  // correct foreground for background mode (double vision)
+  if ($background_mode) {
+    for ($i=0; $i<3; $i++) {
+      $foreground_rgb[$i] = 0.75 * $background_rgb[$i] + 0.25 * $foreground_rgb[$i];
+    }
+  }
+  $background_color = imagecolorallocate($image, $background_rgb[0], $background_rgb[1], $background_rgb[2]);
+  $foreground_color = imagecolorallocate($image, $foreground_rgb[0], $foreground_rgb[1], $foreground_rgb[2]);
+  // precalculate the value ranges for color randomness
+  $foreground_randomness = (int)(variable_get('image_captcha_foreground_color_randomness', 100));
+  if ($foreground_randomness) {
+    if ($background_mode) {
+      $foreground_randomness *= .25;
+    }
+    $foreground_color_range = array();
+    for ($i=0; $i<3; $i++) {
+      $foreground_color_range[$i] = array(max(0, $foreground_rgb[$i] - $foreground_randomness), min(255, $foreground_rgb[$i] + $foreground_randomness));
+    }
+  }
+
+  // set default text color
+  $color = $foreground_color;
+
   // start cursor
   $x = $spacing;
   foreach ($characters as $character) {
@@ -238,13 +289,16 @@ function _image_captcha_image_generator_
     }
     // calculate y position
     $y = .5 * ($height - $character_height);
-    // generate random color
-    if ($light_colors) {
-      $color = imagecolorallocate($image, mt_rand(128, 255), mt_rand(128, 255), mt_rand(128, 255));
-    }
-    else {
-      $color = imagecolorallocate($image, mt_rand(0, 127), mt_rand(0, 127), mt_rand(0, 127));
+    
+    // set text color in case of randomness
+    if ($foreground_randomness) {
+      $color = imagecolorallocate($image,
+        mt_rand($foreground_color_range[0][0], $foreground_color_range[0][1]),
+        mt_rand($foreground_color_range[1][0], $foreground_color_range[1][1]),
+        mt_rand($foreground_color_range[2][0], $foreground_color_range[2][1])
+      );
     }
+    
     // add jitter to position
     $pos_x = $x + mt_rand(-$jittering_x, $jittering_x);
     $pos_y = $y + mt_rand(-$jittering_y, $jittering_y);
