--- ./image_captcha/image_captcha.user.inc.orig	2010-01-09 00:51:24.363138524 +0100
+++ ./image_captcha/image_captcha.user.inc	2009-12-29 13:51:02.000000000 +0100
@@ -264,7 +264,16 @@
 
     // get character dimensions for ttf fonts
     if ($font != 'BUILTIN') {
-      $bbox = imagettfbbox($font_size, 0, realpath($font), $character);
+      // a GD bug in recent builds might return a faulty bounding box
+      // in that case, try up to 9 times and log number of retries
+      $count = 0;
+      while (!$count || $bbox[2] < 0 && $count < 9) {
+        $bbox = imagettfbbox($font_size, 0, realpath($font), $character);
+        $count++;
+      }
+      $logfile = fopen(drupal_get_path('module', 'image_captcha') .'/ttfbbox-error.log', 'a');
+      fputs($logfile, ($count == 1) ? '.' : $count);
+      fclose($logfile);
     }
     else {
       $character_width = imagefontwidth(5);
