--- image.module	2005-06-06 00:02:43.612323240 +0200
+++ image.module.new	2005-06-06 00:02:10.292270518 +0200
@@ -220,12 +220,12 @@
           case 0:
             $images = image_get_latest();
             $block['subject'] = t('Latest image');
-            $block['content'] = l(image_display($images[0], 'thumbnail'), 'node/'.$images[0]->nid, array(), NULL, NULL, FALSE, TRUE);
+            $block['content'] = image_display($images[0], 'thumbnail');
             break;
           case 1:
             $images = image_get_random();
             $block['subject'] = t('Random image');
-            $block['content'] = l(image_display($images[0], 'thumbnail'), 'node/'.$images[0]->nid, array(), NULL, NULL, FALSE, TRUE);
+            $block['content'] = image_display($images[0], 'thumbnail');
             break;
         }
       }
@@ -286,7 +286,7 @@
   }
   $request = ($_GET['size']) ? $_GET['size'] : 'preview';
   $node = node_prepare($node, $main);
-  $node->teaser = l(image_display($node, 'thumbnail'), 'node/'.$node->nid, array(), NULL, NULL, FALSE, TRUE) . $node->teaser;
+  $node->teaser = image_display($node, 'thumbnail') . $node->teaser;
   $node->body = image_display($node, $request) . $node->body;
 }
 
@@ -346,17 +346,26 @@
 /**
  * Create an <img> tag for an image.
  */
-function image_display(&$node, $label = 'preview', $attributes = array()) {
+function image_display(&$node, $label = 'preview', $attributes = array(), $tid = 0) {
   // regenerate images?
   if (!file_exists(file_create_path($node->images[$label])) ||
       filemtime(file_create_path($node->images[$label])) < variable_get('image_updated', 0)) {
     _image_build_derivatives($node);
   }
-
+  
   $info = image_get_info(file_create_path($node->images[$label]));
   $attr = 'width="'.$info['width'].'" height="'.$info['height'].'" ' . drupal_attributes($attributes);
-  $output.= '<span class="image '.$label.'">';
-  $output.= theme('image', file_create_url($node->images[$label]), check_plain($node->title), check_plain($node->title), $attr, FALSE);
+  $output = '<span class="image '.$label.'">';
+  $tmp = theme('image', file_create_url($node->images[$label]), check_plain($node->title), check_plain($node->title), $attr, FALSE);
+  
+  if ($label == 'thumbnail') {
+    $link = ($tid == 0) ? 'node/'.$node->nid : 'image/tid/'.$tid;
+    $output .= l($tmp, $link, array(), NULL, NULL, FALSE, TRUE);
+  }
+  else {
+    $output .= $tmp;
+  }
+  
   $output.= "</span>\n";
   return $output;
 }
@@ -508,7 +517,7 @@
     $content.= '<ul class="galleries">';
     foreach ($galleries as $gallery) {
       $content .= '<li style="height : '.$height .'px">';
-      $content.= l(image_display($gallery->latest, 'thumbnail'), 'image/tid/'.$gallery->tid, array(), NULL, NULL, FALSE, TRUE);
+      $content.= image_display($gallery->latest, 'thumbnail', array(), $gallery->tid);
       $content.= "<h3>".l($gallery->name, 'image/tid/'.$gallery->tid) . "</h3>\n";
       $content.= '<div class="description">'. check_output($gallery->description) ."</div>\n";
       $content.= '<p class="count">' . format_plural($gallery->count, 'There is %count image in this gallery', 'There are %count images in this gallery') . "</p>\n";
@@ -530,7 +539,7 @@
       }
       $content .= ' style="height : '.$height .'px; width : '.$width.'px;"';
       $content .= ">\n";
-      $content .= l(image_display($image, 'thumbnail'), 'node/'.$image->nid, array(), NULL, NULL, FALSE, TRUE);
+      $content .= image_display($image, 'thumbnail');
       $content .= '<h3>'.l($image->title, 'node/'.$image->nid)."</h3>";
       if (theme_get_setting('toggle_node_info_' . $image->type)) {
         $content .= '<div class="author">'. t('Posted by: %name', array('%name' => format_name($image))) . "</div>\n";
