diff --git a/spamspan.module b/spamspan.module
index 61547de..30b8599 100644
--- a/spamspan.module
+++ b/spamspan.module
@@ -110,18 +110,72 @@ function _spamspan_filter_process($text, $filter) {
       </a>                                            # closing tag
       !ix";
 
+  // HTML image tags need to be handled separately, as they may contain base64
+  // encoded images slowing down the email regex function.
+  // Therefore, remove all image contents and add them back later.
+  // See https://drupal.org/node/1243042 for details.
+  _filter_spamspan_escape_images('', TRUE);
+  $text = preg_replace_callback('/<img(.*?)>/', '_filter_spamspan_escape_images', $text);
+
   // The preg_repalce_callback functions below cannot take any additional
   // arguments, so we have to use a global variable to pass the relevant
   // settings.
   $GLOBALS['spamspan_settings'] = $filter->settings;
+
   // Now we can convert all mailto URLs
   $text = preg_replace_callback($mailtopattern, '_spamspan_callback_mailto', $text);
   // and finally, all bare email addresses
-  return preg_replace_callback($emailpattern, '_spamspan_callback_email', $text);
+  $text = preg_replace_callback($emailpattern, '_spamspan_callback_email', $text);
+
+  // Revert back to the original image contents.
+  _filter_spamspan_escape_images('', FALSE);
+  $text = preg_replace_callback('/<!--img(.*?)-->/', '_filter_spamspan_escape_images', $text);
+
+  return $text;
   unset($GLOBALS['spamspan_settings']);
 }
 
 /**
+ * Escapes the contents of HTML image tags.
+ *
+ * Callback for preg_replace_callback() within _spamspan_filter_process().
+ *
+ * @param $match
+ *   An array containing matches to replace from preg_replace_callback(),
+ *   whereas $match[1] is expected to contain the content to be filtered.
+ * @param $escape
+ *   (optional) A Boolean indicating whether to escape (TRUE) or unescape
+ *   comments (FALSE). Defaults to NULL, indicating neither. If TRUE, statically
+ *   cached $comments are reset.
+ */
+function _filter_spamspan_escape_images($match, $escape = NULL) {
+  static $mode, $comments = array();
+
+  if (isset($escape)) {
+    $mode = $escape;
+    if ($escape){
+      $comments = array();
+    }
+    return;
+  }
+
+  // Replace all HTML image with a '<img [hash] />' placeholder.
+  if ($mode) {
+    $content = $match[1];
+    $hash = md5($content);
+    $comments[$hash] = $content;
+    return "<!--img $hash -->";
+  }
+  // Or replace placeholders with actual image contents.
+  else {
+    $hash = $match[1];
+    $hash = trim($hash);
+    $content = $comments[$hash];
+    return "<img $content >";
+  }
+}
+
+/**
  * Settings callback for spamspan filter
  *
  *
