Index: image.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image/image.module,v
retrieving revision 1.315
diff -u -p -r1.315 image.module
--- image.module	25 Aug 2009 12:12:09 -0000	1.315
+++ image.module	26 Aug 2009 08:48:59 -0000
@@ -443,11 +443,8 @@ function image_form_submit($form, &$form
  */
 function image_view($node, $teaser = 0, $page = 0) {
   // Correct any problems with the derivative images.
-  if (!empty($node->rebuild_images)) {
-    image_update($node);
-    watchdog('image', 'Derivative images were regenerated for %title.', array('%title' => $node->title), WATCHDOG_INFO, l(t('view'), 'node/' . $node->nid));
-  }
-
+  _image_build_derivatives_if_needed($node);
+  
   $sizes = image_get_sizes();
   $size = IMAGE_PREVIEW;
   if (isset($_GET['size'])) {
@@ -472,6 +469,22 @@ function image_view($node, $teaser = 0, 
 }
 
 /**
+ * Rebuild derivatives if needed.
+ *
+ * Helper function for image_view. 
+ * Also, any other code that does a node_load() but not a node_view() should 
+ * call this.
+ */
+function _image_build_derivatives_if_needed(&$node) {
+  if (!empty($node->rebuild_images)) {
+    // Possibly TODO: calling a hook implementation here isn't very elegant.
+    // but the code there is tangled and it works, so maybe leave it ;)
+    image_update($node);
+    watchdog('image', 'Derivative images were regenerated for %title.', array('%title' => $node->title), WATCHDOG_INFO, l(t('view'), 'node/' . $node->nid));
+  }  
+}
+
+/**
  * Implementation of hook_load().
  *
  * Loads image data from the database, and sets $node->rebuild_images if a
Index: contrib/image_attach/image_attach.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image/contrib/image_attach/image_attach.module,v
retrieving revision 1.52
diff -u -p -r1.52 image_attach.module
--- contrib/image_attach/image_attach.module	26 Aug 2009 07:52:05 -0000	1.52
+++ contrib/image_attach/image_attach.module	26 Aug 2009 08:48:59 -0000
@@ -79,6 +79,7 @@ function image_attach_block($op = 'list'
           if (isset($node->iid) && $node->iid) {
             $image = node_load($node->iid);
             if (node_access('view', $image)) {
+              _image_build_derivatives_if_needed($image);
               $img = image_display($image, variable_get('image_attach_block_0_size', IMAGE_THUMBNAIL));
               return array(
                 'subject' => t('Attached images'),
@@ -191,6 +192,7 @@ function image_attach_form_alter(&$form,
 
       if (!empty($node->iid)) {
         $image = node_load($node->iid);
+        _image_build_derivatives_if_needed($image);
         $form['image_attach']['image_thumbnail'] = array(
           '#type' => 'item',
           '#title' => t('Thumbnail'),
@@ -385,9 +387,8 @@ function theme_image_attach_teaser($node
       // If the image is restricted, don't show it as an attachment.
       return NULL;
     }
-    if (!empty($image->rebuild_images)) {
-      image_update($image);
-    }
+    _image_build_derivatives_if_needed($node);
+
 
     $class = 'image-attach-teaser' . ($image->status ? '' : ' image-unpublished');
     $info = image_get_info(file_create_path($image->images[$img_size]));
@@ -414,9 +415,7 @@ function theme_image_attach_body($node) 
       // If the image is restricted, don't show it as an attachment.
       return NULL;
     }
-    if (!empty($image->rebuild_images)) {
-      image_update($image);
-    }
+    _image_build_derivatives_if_needed($node);
 
     $class = 'image-attach-body' . ($image->status ? '' : ' image-unpublished');
     $info = image_get_info(file_create_path($image->images[$img_size]));
Index: views/image_handler_field_image_node_image.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image/views/image_handler_field_image_node_image.inc,v
retrieving revision 1.2
diff -u -p -r1.2 image_handler_field_image_node_image.inc
--- views/image_handler_field_image_node_image.inc	15 Aug 2009 20:00:27 -0000	1.2
+++ views/image_handler_field_image_node_image.inc	26 Aug 2009 08:48:59 -0000
@@ -109,12 +109,7 @@ class image_handler_field_image_node_ima
     // image_load() will load the files for all derivatives. Derivatives larger
     // than the original fall back to the original.
     image_load($node);
-
-    // Rebuild derivatives if needed.
-    if (!empty($node->rebuild_images)) {
-      image_update($node);
-      watchdog('image', 'Derivative images were regenerated for %title.', array('%title' => $node->title), WATCHDOG_INFO, l(t('view'), 'node/' . $node->nid));
-    }    
+    _image_build_derivatives_if_needed($node);
 
     return image_display($node, $derivative);
   }
