Index: wp-admin/includes/image-edit.php
===================================================================
--- wp-admin/includes/image-edit.php	(revision 20375)
+++ wp-admin/includes/image-edit.php	(working copy)
@@ -197,45 +197,6 @@
 <?php
 }
 
-function load_image_to_edit($post_id, $mime_type, $size = 'full') {
-	$filepath = get_attached_file($post_id);
-
-	if ( $filepath && file_exists($filepath) ) {
-		if ( 'full' != $size && ( $data = image_get_intermediate_size($post_id, $size) ) ) {
-			$filepath = apply_filters('load_image_to_edit_filesystempath', path_join( dirname($filepath), $data['file'] ), $post_id, $size);
-		}
-	} elseif ( function_exists('fopen') && function_exists('ini_get') && true == ini_get('allow_url_fopen') ) {
-		$filepath = apply_filters('load_image_to_edit_attachmenturl', wp_get_attachment_url($post_id) , $post_id, $size);
-	}
-
-	$filepath = apply_filters('load_image_to_edit_path', $filepath, $post_id, $size);
-	if ( empty($filepath) )
-		return false;
-
-	switch ( $mime_type ) {
-		case 'image/jpeg':
-			$image = imagecreatefromjpeg($filepath);
-			break;
-		case 'image/png':
-			$image = imagecreatefrompng($filepath);
-			break;
-		case 'image/gif':
-			$image = imagecreatefromgif($filepath);
-			break;
-		default:
-			$image = false;
-			break;
-	}
-	if ( is_resource($image) ) {
-		$image = apply_filters('load_image_to_edit', $image, $post_id, $size);
-		if ( function_exists('imagealphablending') && function_exists('imagesavealpha') ) {
-			imagealphablending($image, false);
-			imagesavealpha($image, true);
-		}
-	}
-	return $image;
-}
-
 function wp_stream_image($image, $mime_type, $post_id) {
 	$image = apply_filters('image_save_pre', $image, $post_id);
 
Index: wp-admin/includes/image.php
===================================================================
--- wp-admin/includes/image.php	(revision 20375)
+++ wp-admin/includes/image.php	(working copy)
@@ -43,12 +43,19 @@
  * @param string $dst_file Optional. The destination file to write to.
  * @return string|WP_Error|false New filepath on success, WP_Error or false on failure.
  */
-function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
-	if ( is_numeric( $src_file ) ) // Handle int as attachment ID
-		$src_file = get_attached_file( $src_file );
+function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
+	if ( is_numeric( $src ) ) { // Handle int as attachment ID
+		$src_file = get_attached_file( $src );
+		if ( ! file_exists( $src_file ) ) {
+			$post = get_post( $src );
+			$src = load_image_to_edit( $src, $post->post_mime_type, 'full');
+		} else {
+			$src = wp_load_image( $src_file );
+		}
+	} else {
+		$src = wp_load_image( $src_file );
+	}
 
-	$src = wp_load_image( $src_file );
-
 	if ( !is_resource( $src ) )
 		return new WP_Error( 'error_loading_image', $src, $src_file );
 
@@ -71,6 +78,8 @@
 
 	$dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file );
 
+	wp_mkdir_p( dirname( $dst_file ) );
+
 	if ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) )
 		return $dst_file;
 	else
@@ -339,3 +348,42 @@
 
 	return apply_filters('file_is_displayable_image', $result, $path);
 }
+
+function load_image_to_edit($post_id, $mime_type, $size = 'full') {
+	$filepath = get_attached_file($post_id);
+
+	if ( $filepath && file_exists($filepath) ) {
+		if ( 'full' != $size && ( $data = image_get_intermediate_size($post_id, $size) ) ) {
+			$filepath = apply_filters('load_image_to_edit_filesystempath', path_join( dirname($filepath), $data['file'] ), $post_id, $size);
+		}
+	} elseif ( function_exists('fopen') && function_exists('ini_get') && true == ini_get('allow_url_fopen') ) {
+		$filepath = apply_filters('load_image_to_edit_attachmenturl', wp_get_attachment_url($post_id) , $post_id, $size);
+	}
+
+	$filepath = apply_filters('load_image_to_edit_path', $filepath, $post_id, $size);
+	if ( empty($filepath) )
+		return false;
+
+	switch ( $mime_type ) {
+		case 'image/jpeg':
+			$image = imagecreatefromjpeg($filepath);
+			break;
+		case 'image/png':
+			$image = imagecreatefrompng($filepath);
+			break;
+		case 'image/gif':
+			$image = imagecreatefromgif($filepath);
+			break;
+		default:
+			$image = false;
+			break;
+	}
+	if ( is_resource($image) ) {
+		$image = apply_filters('load_image_to_edit', $image, $post_id, $size);
+		if ( function_exists('imagealphablending') && function_exists('imagesavealpha') ) {
+			imagealphablending($image, false);
+			imagesavealpha($image, true);
+		}
+	}
+	return $image;
+}
Index: wp-admin/custom-header.php
===================================================================
--- wp-admin/custom-header.php	(revision 20375)
+++ wp-admin/custom-header.php	(working copy)
@@ -700,7 +700,13 @@
 			extract($this->step_2_manage_upload());
 		}
 
-		list($width, $height, $type, $attr) = getimagesize( $file );
+		if ( file_exists( $file ) ) {
+			list( $width, $height, $type, $attr ) = getimagesize( $file );
+		} else {
+			$data = wp_get_attachment_metadata( $id );
+			$height = $data[ 'height' ];
+			$width = $data[ 'width' ];
+		}
 
 		$max_width = 0;
 		// For flex, limit size of image displayed to 1500px unless theme says otherwise
@@ -716,7 +722,8 @@
 			&& $width == get_theme_support( 'custom-header', 'width' ) && $height == get_theme_support( 'custom-header', 'height' ) )
 		{
 			// Add the meta-data
-			wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
+			if ( file_exists( $file ) )
+				wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
 			update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
 
 			set_theme_mod('header_image', esc_url($url));
@@ -724,7 +731,7 @@
 			return $this->finished();
 		} elseif ( $width > $max_width ) {
 			$oitar = $width / $max_width;
-			$image = wp_crop_image($file, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
+			$image = wp_crop_image($id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
 			if ( is_wp_error( $image ) )
 				wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
 
