Index: wp-includes/default-filters.php
===================================================================
--- wp-includes/default-filters.php	(revision 3850)
+++ wp-includes/default-filters.php	(working copy)
@@ -114,6 +114,11 @@
 // Misc filters
 add_filter('option_ping_sites', 'privacy_ping_filter');
 
+// Attachments
+add_filter('wp_thumbnail_attachment_image/jpeg', 'wp_image_thumbnail', 10, -1);
+add_filter('wp_thumbnail_attachment_image/gif', 'wp_image_thumbnail', 10, -1);
+add_filter('wp_thumbnail_attachment_image/png', 'wp_image_thumbnail', 10, -1);
+
 // Actions
 add_action('wp_head', 'rsd_link');
 add_action('publish_future_post', 'wp_publish_post', 10, 1);
Index: wp-includes/functions-post.php
===================================================================
--- wp-includes/functions-post.php	(revision 3850)
+++ wp-includes/functions-post.php	(working copy)
@@ -355,15 +355,28 @@
 
 	clean_post_cache($post_ID);
 
-	if ( $update) {
+	if ( $update )
 		do_action('edit_attachment', $post_ID);
-	} else {
+	else
 		do_action('add_attachment', $post_ID);
-	}
 
 	return $post_ID;
 }
 
+function wp_thumbnail_attachment( $post_ID ) {
+	$attachment =& get_post( $post_ID );
+	$meta = get_post_meta( $post_ID, '_wp_attachment_metadata', true );
+	$file = get_post_meta( $post_ID, '_wp_attached_file', true );
+
+	$meta = apply_filters( 'wp_thumbnail_attachment_' . strtolower($attachment->post_mime_type), $meta, $post_ID, $file );
+
+	if ( !$meta || is_wp_error( $meta ) )
+		add_post_meta( $post_ID, '_wp_attachment_metadata', array() );
+	else
+		add_post_meta( $post_ID, '_wp_attachment_metadata', $meta );
+	return $meta;
+}
+
 function wp_delete_attachment($postid) {
 	global $wpdb;
 	$postid = (int) $postid;
Index: wp-admin/inline-uploading.php
===================================================================
--- wp-admin/inline-uploading.php	(revision 3850)
+++ wp-admin/inline-uploading.php	(working copy)
@@ -71,37 +71,19 @@
 	);
 
 // Save the data
-$id = wp_insert_attachment($attachment, $file, $post);
+$id = wp_insert_attachment( $attachment, $file, $post );
 
-if ( preg_match('!^image/!', $attachment['post_mime_type']) ) {
-	// Generate the attachment's postmeta.
-	$imagesize = getimagesize($file);
-	$imagedata['width'] = $imagesize['0'];
-	$imagedata['height'] = $imagesize['1'];
-	list($uwidth, $uheight) = get_udims($imagedata['width'], $imagedata['height']);
-	$imagedata['hwstring_small'] = "height='$uheight' width='$uwidth'";
-	$imagedata['file'] = $file;
+$error = wp_thumbnail_attachment( $id );
 
-	add_post_meta($id, '_wp_attachment_metadata', $imagedata);
-
-	if ( $imagedata['width'] * $imagedata['height'] < 3 * 1024 * 1024 ) {
-		if ( $imagedata['width'] > 128 && $imagedata['width'] >= $imagedata['height'] * 4 / 3 )
-			$thumb = wp_create_thumbnail($file, 128);
-		elseif ( $imagedata['height'] > 96 )
-			$thumb = wp_create_thumbnail($file, 96);
-
-		if ( @file_exists($thumb) ) {
-			$newdata = $imagedata;
-			$newdata['thumb'] = basename($thumb);
-			update_post_meta($id, '_wp_attachment_metadata', $newdata, $imagedata);
-		} else {
-			$error = $thumb;
-		}
-	}
-} else {
-	add_post_meta($id, '_wp_attachment_metadata', array());
+if ( is_wp_error( $error ) ) {
+	echo "<div class='error'>\n\t<ul>\n";
+	foreach ( $error->get_error_messages() as $message )
+		 echo "\t\t<li>$message</li>\n";
+	echo "\t</ul>\n\t<a href='" . basename(__FILE__) . "?post=$post&all=$all&action=view&start=0". "'>" . __('Continue') . "</a>\n</div>\n";
+	die();
 }
 
+
 header("Location: " . basename(__FILE__) . "?post=$post&all=$all&action=view&start=0");
 die();
 
Index: wp-admin/admin-functions.php
===================================================================
--- wp-admin/admin-functions.php	(revision 3850)
+++ wp-admin/admin-functions.php	(working copy)
@@ -771,98 +771,102 @@
 	return $wpdb->get_col("SELECT cat_ID FROM $wpdb->categories WHERE category_parent = $parent ORDER BY link_count DESC");
 }
 
-function wp_create_thumbnail($file, $max_side, $effect = '') {
+function wp_image_thumbnail( $meta, $post_ID, $file ) {
+	$attachment =& get_post( $post_ID );
 
-		// 1 = GIF, 2 = JPEG, 3 = PNG
+	if ( is_wp_error( $meta ) || isset($meta['thumb']) )
+		return $meta;
+	if ( !is_array($meta) )
+		$meta = array();
 
-	if (file_exists($file)) {
-		$type = getimagesize($file);
+	if ( preg_match('!^image/!', $attachment->post_mime_type) ) {
+		// Generate the attachment's postmeta.
+		$imagesize = getimagesize($file);
+		$meta['width'] = $imagesize['0'];
+		$meta['height'] = $imagesize['1'];
+		list($uwidth, $uheight) = get_udims( $meta['width'], $meta['height'] );
+		$meta['hwstring_small'] = "height='$uheight' width='$uwidth'";
+		$meta['file'] = $file;
 
-		// if the associated function doesn't exist - then it's not
-		// handle. duh. i hope.
-
-		if (!function_exists('imagegif') && $type[2] == 1) {
-			$error = __('Filetype not supported. Thumbnail not created.');
+		if ( $meta['width'] * $meta['height'] < 3 * 1024 * 1024 ) {
+			if ( $meta['width'] > 128 && $meta['width'] >= $meta['height'] * 4 / 3 )
+				$thumb = wp_create_thumbnail( $file, 128 );
+			elseif ( $meta['height'] > 96 )
+				$thumb = wp_create_thumbnail( $file, 96 );
+			if ( @file_exists($thumb) )
+				$meta['thumb'] = basename($thumb);
+			else
+				return $thumb;
 		}
-		elseif (!function_exists('imagejpeg') && $type[2] == 2) {
-			$error = __('Filetype not supported. Thumbnail not created.');
-		}
-		elseif (!function_exists('imagepng') && $type[2] == 3) {
-			$error = __('Filetype not supported. Thumbnail not created.');
-		} else {
+	}
+	return $meta;
+}
 
-			// create the initial copy from the original file
-			if ($type[2] == 1) {
-				$image = imagecreatefromgif($file);
-			}
-			elseif ($type[2] == 2) {
-				$image = imagecreatefromjpeg($file);
-			}
-			elseif ($type[2] == 3) {
-				$image = imagecreatefrompng($file);
-			}
+function wp_create_thumbnail( $file, $max_side, $effect = '' ) {
+	if ( !file_exists($file) )
+		return new WP_Error( 'thumbnail', __('File not found') );
 
-			if (function_exists('imageantialias'))
-				imageantialias($image, TRUE);
+	$image_attr = getimagesize($file);
 
-			$image_attr = getimagesize($file);
+	// If the associated function doesn't exist - then it's not handled.
+	switch ( $image_attr[2] ) : // 1 = GIF, 2 = JPEG, 3 = PNG
+	case 1:
+		$image_func = 'imagegif';
+		$image_create_func = 'imagecreatefromgif';
+		break;
+	case 2:
+		$image_func = 'imagejpeg';
+		$image_create_func = 'imagecreatefromjpeg';
+		break;
+	case 3:
+		$image_func = 'imagepng';
+		$image_create_func = 'imagecreatefrompng';
+		break;
+	default:
+		return new WP_Error( 'thumbnail', __('Unknown filetype. Thumbnail not created.') );
+		break;
+	endswitch;
 
-			// figure out the longest side
+	if ( !function_exists($image_func) )
+		return new WP_Error( 'thumbnail', __('Filetype not supported. Thumbnail not created.') );
 
-			if ($image_attr[0] > $image_attr[1]) {
-				$image_width = $image_attr[0];
-				$image_height = $image_attr[1];
-				$image_new_width = $max_side;
+	// create the initial copy from the original file
+	$image = $image_create_func($file);
 
-				$image_ratio = $image_width / $image_new_width;
-				$image_new_height = $image_height / $image_ratio;
-				//width is > height
-			} else {
-				$image_width = $image_attr[0];
-				$image_height = $image_attr[1];
-				$image_new_height = $max_side;
+	if ( function_exists('imageantialias') )
+		imageantialias($image, TRUE);
 
-				$image_ratio = $image_height / $image_new_height;
-				$image_new_width = $image_width / $image_ratio;
-				//height > width
-			}
+	// figure out the longest side
+	if ( $image_attr[0] > $image_attr[1] ) { // width > height
+		$image_width = $image_attr[0];
+		$image_height = $image_attr[1];
+		$image_new_width = $max_side;
 
-			$thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
-			@ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);
+		$image_ratio = $image_width / $image_new_width;
+		$image_new_height = $image_height / $image_ratio;
+	} else { // height > width
+		$image_width = $image_attr[0];
+		$image_height = $image_attr[1];
+		$image_new_height = $max_side;
 
-			// If no filters change the filename, we'll do a default transformation.
-			if ( basename($file) == $thumb = apply_filters('thumbnail_filename', basename($file)) )
-				$thumb = preg_replace('!(\.[^.]+)?$!', __('.thumbnail').'$1', basename($file), 1);
+		$image_ratio = $image_height / $image_new_height;
+		$image_new_width = $image_width / $image_ratio;
+	}
 
-			$thumbpath = str_replace(basename($file), $thumb, $file);
+	$thumbnail = imagecreatetruecolor($image_new_width, $image_new_height);
+	@ imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $image_new_width, $image_new_height, $image_attr[0], $image_attr[1]);
 
-			// move the thumbnail to it's final destination
-			if ($type[2] == 1) {
-				if (!imagegif($thumbnail, $thumbpath)) {
-					$error = __("Thumbnail path invalid");
-				}
-			}
-			elseif ($type[2] == 2) {
-				if (!imagejpeg($thumbnail, $thumbpath)) {
-					$error = __("Thumbnail path invalid");
-				}
-			}
-			elseif ($type[2] == 3) {
-				if (!imagepng($thumbnail, $thumbpath)) {
-					$error = __("Thumbnail path invalid");
-				}
-			}
+	// If no filters change the filename, we'll do a default transformation.
+	if ( basename($file) == $thumb = apply_filters( 'thumbnail_filename', basename($file) ) )
+		$thumb = preg_replace('!(\.[^.]+)?$!', __('.thumbnail').'$1', basename($file), 1);
 
-		}
-	} else {
-		$error = __('File not found');
-	}
+	$thumbpath = str_replace(basename($file), $thumb, $file);
 
-	if (!empty ($error)) {
-		return $error;
-	} else {
-		return $thumbpath;
-	}
+	// move the thumbnail to it's final destination
+	if ( !$image_func($thumbnail, $thumbpath) )
+		return new WP_Error( 'thumbnail', __("Thumbnail path invalid") );
+
+	return $thumbpath;
 }
 
 // Some postmeta stuff
