? image_captcha/.DS_Store
? image_captcha/fonts/.DS_Store
? image_captcha/fonts/.gitignore
? image_captcha/fonts/1456Gutenberg.TTF
? image_captcha/fonts/Army.ttf
? image_captcha/fonts/BABYK___.TTF
? image_captcha/fonts/actionj.ttf
? image_captcha/fonts/dropacha.ttf
? image_captcha/fonts/skinck.ttf
? image_captcha/fonts/subeve.ttf
? image_captcha/fonts/tiza.ttf
? image_captcha/fonts/Tesox/.DS_Store
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.30
diff -u -b -u -p -r1.30 image_captcha.admin.inc
--- image_captcha/image_captcha.admin.inc	15 Dec 2009 23:53:37 -0000	1.30
+++ image_captcha/image_captcha.admin.inc	4 Feb 2010 00:16:36 -0000
@@ -22,7 +22,7 @@ function image_captcha_settings_form() {
 
   // First some error checking.
   $setup_status = _image_captcha_check_setup(FALSE);
-  if ($setup_status & IMAGE_CAPTCHA_ERROR_NO_GDLIB_WITH_JPEG) {
+  if ($setup_status & IMAGE_CAPTCHA_ERROR_NO_GDLIB) {
     drupal_set_message(t(
       'The Image CAPTCHA module can not generate images because your PHP setup does not support it (no <a href="!gdlib">GD library</a> with JPEG support).',
       array('!gdlib' => 'http://php.net/manual/en/book.image.php')
Index: image_captcha/image_captcha.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/image_captcha/image_captcha.install,v
retrieving revision 1.10
diff -u -b -u -p -r1.10 image_captcha.install
--- image_captcha/image_captcha.install	16 Dec 2009 00:11:41 -0000	1.10
+++ image_captcha/image_captcha.install	4 Feb 2010 00:16:36 -0000
@@ -7,6 +7,30 @@
  */
 
 /**
+ * Implementation of hook_requirements().
+ */
+function image_captcha_requirements($phase) {
+  $requirements = array();
+  $t = get_t();
+  if ($phase == 'install') {
+    // _image_captcha_check_setup() is defined in image_captcha.module.
+    module_load_include('module', 'image_captcha');
+    // Check if the GD library is available and raise an error when not.
+    if (_image_captcha_check_setup(FALSE) & IMAGE_CAPTCHA_ERROR_NO_GDLIB) {
+      $requirements['image_captcha_requires_gd'] = array(
+        'title' => $t('Image CAPTCHA requires GD library'),
+        'description' =>
+          $t('The Image CAPTCHA module can not be installed because your PHP setup does not provide the <a href="!gddoc">GD library</a>, which is required to generate images.',
+            array('!gddoc' => 'http://www.php.net/manual/en/book.image.php',)
+          ),
+        'severity' => REQUIREMENT_ERROR,
+      );
+    }
+  }
+  return $requirements;
+}
+
+/**
  * On uninstall: remove module variables and clear variable cache
  */
 function image_captcha_uninstall() {
Index: image_captcha/image_captcha.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/captcha/image_captcha/image_captcha.module,v
retrieving revision 1.33
diff -u -b -u -p -r1.33 image_captcha.module
--- image_captcha/image_captcha.module	15 Dec 2009 23:53:37 -0000	1.33
+++ image_captcha/image_captcha.module	4 Feb 2010 00:16:36 -0000
@@ -6,13 +6,10 @@
  * Implementation of image CAPTCHA for use with the CAPTCHA module
  */
 
-// TODO: add hook_requirements to avoid installing when there is no GD support
-
 define('IMAGE_CAPTCHA_ALLOWED_CHARACTERS', 'aAbBCdEeFfGHhijKLMmNPQRrSTtWXYZ23456789');
 
 // Setup status flags.
-define('IMAGE_CAPTCHA_SETUP_OK', 0);
-define('IMAGE_CAPTCHA_ERROR_NO_GDLIB_WITH_JPEG', 1);
+define('IMAGE_CAPTCHA_ERROR_NO_GDLIB', 1);
 define('IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT', 2);
 define('IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM', 4);
 
@@ -137,21 +134,35 @@ function _image_captcha_utf8_split($str)
 }
 
 /**
- * Helper function for checking if the requirements for the Image CAPTCHA are met.
+ * Helper function for checking the setup of the Image CAPTCHA.
+ *
+ * The image CAPTCHA requires at least the GD PHP library.
+ * Support for TTF is recommended and the enabled
+ * font files should be readable.
+ * This functions checks these things.
  *
  * @param $check_fonts whether or not the enabled fonts should be checked.
  *
  * @return status code: bitwise 'OR' of status flags like
- *   IMAGE_CAPTCHA_ERROR_NO_GDLIB_WITH_JPEG, IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT,
+ *   IMAGE_CAPTCHA_ERROR_NO_GDLIB, IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT,
  *   IMAGE_CAPTCHA_ERROR_TTF_FILE_READ_PROBLEM.
- *   When no problems, the status is IMAGE_CAPTCHA_SETUP_OK.
  */
 function _image_captcha_check_setup($check_fonts=TRUE) {
   // Start clean.
-  $status = IMAGE_CAPTCHA_SETUP_OK;
-  // Check GD library and is TTF support.
+  $status = 0;
+  // Check if we can use the GD library.
+  // Note that we are only checking
+  // for the existence of the imagejpeg function.
+  // We could also check for imagepng, which can also be used
+  // (optionally) for the image CAPTCHA by the site admin.
+  // However, this incurs extra complexity in the setup checking
+  // (more constants to define) and in the caller functions
+  // (more situations to check for).
+  // We take this shortcut (only checking for imagejpeg) because
+  // it's probably pretty safe to assume that imagepng
+  // is available when imagejpeg is available.
   if (!function_exists('imagejpeg')) {
-    $status = $status | IMAGE_CAPTCHA_ERROR_NO_GDLIB_WITH_JPEG;
+    $status = $status | IMAGE_CAPTCHA_ERROR_NO_GDLIB;
   }
   if (!function_exists('imagettftext')) {
     $status = $status | IMAGE_CAPTCHA_ERROR_NO_TTF_SUPPORT;
@@ -173,8 +184,8 @@ function _image_captcha_check_setup($che
 function image_captcha_captcha($op, $captcha_type='', $captcha_sid=NULL) {
   switch ($op) {
     case 'list':
-      // only offer image CAPTCHA if possible to generate an image CAPTCHA
-      if (_image_captcha_check_setup() == IMAGE_CAPTCHA_SETUP_OK) {
+      // Only offer the image CAPTCHA if it is possible to generate an image on this setup.
+      if (!(_image_captcha_check_setup() & IMAGE_CAPTCHA_ERROR_NO_GDLIB)) {
         return array('Image');
       }
       else {
