Index: node_gallery.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_gallery/node_gallery.module,v
retrieving revision 1.18.2.148
diff -u -p -r1.18.2.148 node_gallery.module
--- node_gallery.module	16 Dec 2010 20:12:16 -0000	1.18.2.148
+++ node_gallery.module	17 Dec 2010 20:26:49 -0000
@@ -299,6 +299,10 @@ function node_gallery_theme() {
       'arguments' => array('element' => NULL),
       'function' => 'theme_node_gallery_formatter_nextimagelink',
     );
+    $themes['node_gallery_formatter_'. $preset['presetname'] .'_gallerylink'] = array(
+      'arguments' => array('element' => NULL),
+      'function' => 'theme_node_gallery_formatter_gallerylink',
+    );
   }
   foreach ($themes as &$theme) {
     $theme['path'] = $path;
@@ -1049,6 +1053,11 @@ function node_gallery_field_formatter_in
       'field types' => array('image', 'filefield'),
       'description' => t('Displays images and links them to the next image in the gallery.'),
     );
+    $formatters[$preset['presetname'] .'_gallerylink'] = array(
+      'label' => t('@preset linked to gallery', array('@preset' => $preset['presetname'])),
+      'field types' => array('image', 'filefield'),
+      'description' => t('Displays images and links them to the gallery.'),
+    );
   }
   return $formatters;
 }
Index: theme/theme.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/node_gallery/theme/theme.inc,v
retrieving revision 1.2.2.42
diff -u -p -r1.2.2.42 theme.inc
--- theme/theme.inc	16 Dec 2010 14:29:02 -0000	1.2.2.42
+++ theme/theme.inc	17 Dec 2010 21:08:19 -0000
@@ -110,19 +110,15 @@ function theme_node_gallery_formatter_ne
     return '';
   }
 
-  // Extract the preset name from the formatter name.
-  // Note: this is the default imagecache way, no hack
-  $presetname = substr($element['#formatter'], 0, strrpos($element['#formatter'], '_'));
-
   // If node type is not in a gallery relationship or gid is not set, just render the default formatter.
+  $imagetag = theme_imagecache_formatter_default($element);
   $node = $element['#node'];
   if (!in_array($node->type, (array)node_gallery_get_types('image'))
           || !isset($node->gid)) {
-    return theme_imagecache_formatter_default($element);
+    return $imagetag;
   }
   $relationship = node_gallery_get_relationship(NULL, $node->type);
   $next = node_gallery_get_next_image($node->gid, $node->nid);
-  $imagetag = theme_imagecache_formatter_default($element);
   if ($next !== NULL) {
     $class = 'imagefield image-nextimagelink imagefield-'. $element['#field_name'];
     $options = array('attributes' => array('class' => $class), 'html' => TRUE);
@@ -136,3 +132,20 @@ function theme_node_gallery_formatter_ne
     return $imagetag;
   }
 }
+
+/**
+ * Link an image to its gallery.
+ */
+function theme_node_gallery_formatter_gallerylink($element) {
+  if (empty($element['#item']['fid'])) {
+    return '';
+  }
+  $imagetag = theme_imagecache_formatter_default($element);
+  if (!in_array($element['#node']->type, (array)node_gallery_get_types('image'))) {
+    return $imagetag;
+  }
+  $node = node_load($element['#node']->nid);  
+  $class = 'imagefield image-gallerylink imagefield-'. $element['#field_name'];
+  $options = array('attributes' => array('class' => $class), 'html' => TRUE);
+  return l($imagetag, 'node/'. $node->gid, $options);
+}
