Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php	(revision 7201)
+++ wp-includes/post.php	(working copy)
@@ -2180,6 +2180,15 @@
 		}
 	}
 
+	// remove intermediate images if there are any
+	$sizes = apply_filters('intermediate_image_sizes', array('thumbnail', 'medium'));
+	foreach ( $sizes as $size ) {
+		if ( $intermediate = image_get_intermediate_size($postid, $size) ) {
+			$intermediate_file = apply_filters('wp_delete_file', $intermediate['path']);
+			@ unlink($intermediate_file);
+		}
+	}
+
 	$file = apply_filters('wp_delete_file', $file);
 
 	if ( ! empty($file) )
Index: wp-includes/media.php
===================================================================
--- wp-includes/media.php	(revision 7201)
+++ wp-includes/media.php	(working copy)
@@ -79,7 +79,9 @@
 		list( $width, $height ) = image_constrain_size_for_editor( $meta['width'], $meta['height'], $size );
 	}
 
-	return array( $img_url, $width, $height );
+	if ( $img_url)
+		return array( $img_url, $width, $height );
+	return false;
 
 }
 
@@ -253,7 +255,14 @@
 	if ( empty($imagedata['sizes'][$size]) )
 		return false;
 		
-	return $imagedata['sizes'][$size];
+	$data = $imagedata['sizes'][$size];
+	// include the full filesystem path of the intermediate file
+	if ( empty($data['path']) && !empty($data['file']) ) {
+		$file_url = wp_get_attachment_url($post_id);
+		$data['path'] = path_join( dirname($imagedata['file']), $data['file'] );
+		$data['url'] = path_join( dirname($file_url), $data['file'] );
+	}
+	return $data;
 }
 
 // get an image to represent an attachment - a mime icon for files, thumbnail or intermediate size for images
@@ -290,7 +299,6 @@
 	return $html;
 }
 
-
 add_shortcode('gallery', 'gallery_shortcode');
 
 function gallery_shortcode($attr) {
