--- image_captcha.user.inc	2009-09-18 01:16:32.000000000 +0200
+++ new_image_captcha.user.inc	2009-09-19 10:55:22.984375000 +0200
@@ -1,5 +1,5 @@
 <?php
-// $Id: image_captcha.user.inc,v 1.20 2009/09/17 23:16:32 soxofaan Exp $
+// $Id: image_captcha.user.inc,v 1.19-x 2009/09/19 22:16:48 Machi27 Exp $
 
 /**
  * @file
@@ -29,16 +29,30 @@ function image_captcha_image($captcha_si
       watchdog('CAPTCHA', 'Generation of image CAPTCHA failed. Check your image CAPTCHA configuration and especially the used font.', array(), WATCHDOG_ERROR);
       exit();
     }
-    // Send the image resource as an image to the client
-    drupal_set_header("Content-type: image/jpeg");
-    // Following header is needed for Konqueror, which would re-request the image
-    // on a mouseover event, which failes because the image can only be generated
-    // once. This cache directive forces Konqueror to use cache instead of
-    // re-requesting
-    drupal_set_header("Cache-Control: max-age=3600, must-revalidate");
-    // print the image as jpg to the client
-    imagejpeg($image);
-    // Clean up
+    // Check image type and Send the image resource as an image to the client
+	$img_type = variable_get('image_captcha_image_format');
+	if ($img_type == 1 ) {
+	  // Send the image resource as an image to the client
+	  drupal_set_header("Content-type: image/jpeg");
+      // Following header is needed for Konqueror, which would re-request the image
+      // on a mouseover event, which failes because the image can only be generated
+      // once. This cache directive forces Konqueror to use cache instead of
+      // re-requesting	  
+	  drupal_set_header("Cache-Control: max-age=3600, must-revalidate");
+	  // print the image as jpg to the client
+	  imagejpeg($image);
+	  } else
+	  {
+ 	  // Send the image resource as an image to the client
+      drupal_set_header("Content-type: image/png"); 
+      // Following header is needed for Konqueror, which would re-request the image
+      // on a mouseover event, which failes because the image can only be generated
+      // once. This cache directive forces Konqueror to use cache instead of
+      // re-requesting	  
+	  drupal_set_header("Cache-Control: max-age=3600, must-revalidate");
+	  // print the image as png to the client
+      imagepng($image);
+	  }
     imagedestroy($image);
   }
   exit();
@@ -87,8 +101,15 @@ function _image_captcha_generate_image($
   }
 
   // get background color and paint
+  $img_type = variable_get('image_captcha_image_format');
   $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]);
+  if ($img_type == 3) {
+      $background_color = imagecolorallocate($image, $background_rgb[0], $background_rgb[1], $background_rgb[2]);
+      imagecolortransparent($image, $background_color);
+     }	else
+     {
+    $background_color = imagecolorallocate($image, $background_rgb[0], $background_rgb[1], $background_rgb[2]);
+  }
   imagefilledrectangle($image, 0, 0, $width, $height, $background_color);
 
   // draw text
@@ -111,7 +132,7 @@ function _image_captcha_generate_image($
   }
 
   // Distort the image.
-  $distortion_amplitude = .25 * $font_size * variable_get('image_captcha_distortion_amplitude', 0) / 10.0;
+  $distortion_amplitude = .25 * $font_size * variable_get('image_captcha_distortion_amplitude', 6) / 10.0;
   if ($distortion_amplitude > 1) {
     // distortion parameters
     $wavelength_xr = (2+3*lcg_value())*$font_size;
