Index: src/wp-admin/includes/image.php
===================================================================
--- src/wp-admin/includes/image.php	(revision 45895)
+++ src/wp-admin/includes/image.php	(working copy)
@@ -141,7 +141,7 @@
 		return $image_meta;
 	}
 
-	$image_file = get_attached_file( $attachment_id );
+	$image_file = wp_get_original_attachment_image( $attachment_id );
 
 	// This also updates the image meta.
 	return _wp_make_subsizes( $missing_sizes, $image_file, $image_meta, $attachment_id );
@@ -156,26 +156,81 @@
  * @since 5.3.0
  *
  * @param string $file          Full path to the image file.
- * @param array  $image_meta    The attachment meta data array.
  * @param int    $attachment_id Attachment Id to process.
  * @return array The attachment metadata with updated `sizes` array. Includes an array of errors encountered while resizing.
  */
-function wp_create_image_subsizes( $file, $image_meta, $attachment_id ) {
-	if ( empty( $image_meta ) || ! isset( $image_meta['width'], $image_meta['height'] ) ) {
-		// New uploaded image.
-		$imagesize            = @getimagesize( $file );
-		$image_meta['width']  = $imagesize[0];
-		$image_meta['height'] = $imagesize[1];
+function wp_create_image_subsizes( $file, $attachment_id ) {
+	$imagesize  = @getimagesize( $file );
 
-		// Make the file path relative to the upload dir.
-		$image_meta['file'] = _wp_relative_upload_path( $file );
+	// Default image meta
+	$image_meta = array(
+		'width'  => $imagesize[0],
+		'height' => $imagesize[1],
+		'file'   => _wp_relative_upload_path( $file ),
+		'sizes'  => array(),
+	);
 
-		// Fetch additional metadata from EXIF/IPTC.
-		$exif_meta = wp_read_image_metadata( $file );
+	// Fetch additional metadata from EXIF/IPTC.
+	$exif_meta = wp_read_image_metadata( $file );
 
-		if ( $exif_meta ) {
-			$image_meta['image_meta'] = $exif_meta;
+	if ( $exif_meta ) {
+		$image_meta['image_meta'] = $exif_meta;
+	}
+
+	/**
+	 * Filters the "BIG image" threshold value.
+	 *
+	 * If the original image width or height is above the threshold, it will be scaled down. The threshold is
+	 * used as max width or height. The scaled down image will be used as the largest available size, including
+	 * the `_wp_attached_file` post meta value.
+	 *
+	 * Returning `false` from the filter callback will disable this behavior.
+	 *
+	 * @since 5.3.0
+	 *
+	 * @param array  $image_meta    The new image meta data array. Note that `sizes` is empty as sub-sizes
+	 *                              haven't been created yet.
+	 * @param string $file          Full path to the uploaded image file.
+	 * @param int    $attachment_id Attachment post ID.
+	 */
+	$threshold = (int) apply_filters( 'big_image_size_threshold', 2560, $image_meta, $file, $attachment_id );
+
+	// If the original size is over the threshold, resize the image,
+	// and use it as the "full" size.
+	if ( $threshold && ( $image_meta['width'] > $threshold || $image_meta['height'] > $threshold ) ) {
+		$editor = wp_get_image_editor( $file );
+
+		if ( is_wp_error( $editor ) ) {
+			// This image cannot be edited.
+			return $image_meta;
 		}
+
+		// Resize the image
+		$resized = $editor->resize( $threshold, $threshold );
+
+		if ( ! is_wp_error( $resized ) ) {
+			// TODO: can EXIF rotate here.
+			// By default the editor will append `{width}x{height}` to the file name of the resized image.
+			// Perhaps append `-scaled` to the new image name to make it easy to recognize?.
+			$saved = $editor->save( $editor->generate_filename( 'scaled' ) );
+
+			if ( ! is_wp_error( $saved ) ) {
+				$new_file = $saved['path'];
+
+				// Update the attached file meta.
+				update_attached_file( $attachment_id, $new_file );
+
+				// Width and height of the new image.
+				$image_meta['width']  = $saved['width'];
+				$image_meta['height'] = $saved['height'];
+
+				// Make the file path relative to the upload dir.
+				$image_meta['file'] = _wp_relative_upload_path( $new_file );
+
+				// Store the original image file name in image_meta.
+				$image_meta['original_image'] = wp_basename( $file );
+			}
+		}
 	}
 
 	$new_sizes = wp_get_registered_image_subsizes();
@@ -226,74 +281,80 @@
 		$image_meta['sizes'] = array();
 	}
 
-	if ( ! empty( $new_sizes ) ) {
-		// Sort the image sub-sizes in order of priority when creating them.
-		// This ensures there is an appropriate sub-size the user can access immediately
-		// even when there was an error and not all sub-sizes were created.
-		$priority = array(
-			'medium'       => null,
-			'large'        => null,
-			'thumbnail'    => null,
-			'medium_large' => null,
-		);
+	if ( empty( $new_sizes ) ) {
+		// Nothing to do...
+		return $image_meta;
+	}
 
-		$new_sizes = array_filter( array_merge( $priority, $new_sizes ) );
+	// Sort the image sub-sizes in order of priority when creating them.
+	// This ensures there is an appropriate sub-size the user can access immediately
+	// even when there was an error and not all sub-sizes were created.
+	$priority = array(
+		'medium'       => null,
+		'large'        => null,
+		'thumbnail'    => null,
+		'medium_large' => null,
+	);
 
-		$editor = wp_get_image_editor( $file );
+	$new_sizes = array_filter( array_merge( $priority, $new_sizes ) );
 
-		if ( ! is_wp_error( $editor ) ) {
-			if ( method_exists( $editor, 'make_subsize' ) ) {
-				foreach ( $new_sizes as $new_size_name => $new_size_data ) {
-					$new_size_meta = $editor->make_subsize( $new_size_data );
+	$editor = wp_get_image_editor( $file );
 
-					if ( is_wp_error( $new_size_meta ) ) {
-						$error_code = $new_size_meta->get_error_code();
+	if ( is_wp_error( $editor ) ) {
+		// The image cannot be edited.
+		return $image_meta;
+	}
 
-						if ( $error_code === 'error_getting_dimensions' ) {
-							// Ignore errors when `image_resize_dimensions()` returns false.
-							// They mean that the requested size is larger than the original image and should be skipped.
-							continue;
-						}
+	if ( method_exists( $editor, 'make_subsize' ) ) {
+		foreach ( $new_sizes as $new_size_name => $new_size_data ) {
+			$new_size_meta = $editor->make_subsize( $new_size_data );
 
-						if ( empty( $image_meta['subsize_errors'] ) ) {
-							$image_meta['subsize_errors'] = array();
-						}
+			if ( is_wp_error( $new_size_meta ) ) {
+				$error_code = $new_size_meta->get_error_code();
 
-						$error = array(
-							'error_code'    => $error_code,
-							'error_message' => $new_size_meta->get_error_message(),
-						);
+				if ( $error_code === 'error_getting_dimensions' ) {
+					// Ignore errors when `image_resize_dimensions()` returns false.
+					// They mean that the requested size is larger than the original image and should be skipped.
+					continue;
+				}
 
-						// Store the error code and error message for displaying in the UI.
-						$image_meta['subsize_errors'][ $new_size_name ] = $error;
-					} else {
-						// The sub-size was created successfully.
-						// Clear out previous errors in creating this subsize.
-						if ( ! empty( $image_meta['subsize_errors'][ $new_size_name ] ) ) {
-							unset( $image_meta['subsize_errors'][ $new_size_name ] );
-						}
+				if ( empty( $image_meta['subsize_errors'] ) ) {
+					$image_meta['subsize_errors'] = array();
+				}
 
-						if ( empty( $image_meta['subsize_errors'] ) ) {
-							unset( $image_meta['subsize_errors'] );
-						}
+				$error = array(
+					'error_code'    => $error_code,
+					'error_message' => $new_size_meta->get_error_message(),
+				);
 
-						// Save the size meta value.
-						$image_meta['sizes'][ $new_size_name ] = $new_size_meta;
-					}
-
-					wp_update_attachment_metadata( $attachment_id, $image_meta );
+				// Store the error code and error message for displaying in the UI.
+				$image_meta['subsize_errors'][ $new_size_name ] = $error;
+			} else {
+				// The sub-size was created successfully.
+				// Clear out previous errors in creating this subsize.
+				if ( ! empty( $image_meta['subsize_errors'][ $new_size_name ] ) ) {
+					unset( $image_meta['subsize_errors'][ $new_size_name ] );
 				}
-			} else {
-				// Fall back to `$editor->multi_resize()`.
-				$created_sizes = $editor->multi_resize( $new_sizes );
 
-				if ( ! empty( $created_sizes ) ) {
-					$image_meta['sizes'] = array_merge( $image_meta['sizes'], $created_sizes );
+				if ( empty( $image_meta['subsize_errors'] ) ) {
 					unset( $image_meta['subsize_errors'] );
-					wp_update_attachment_metadata( $attachment_id, $image_meta );
 				}
+
+				// Save the size meta value.
+				$image_meta['sizes'][ $new_size_name ] = $new_size_meta;
 			}
+
+			wp_update_attachment_metadata( $attachment_id, $image_meta );
 		}
+	} else {
+		// Fall back to `$editor->multi_resize()`.
+		$created_sizes = $editor->multi_resize( $new_sizes );
+
+		if ( ! empty( $created_sizes ) ) {
+			$image_meta['sizes'] = array_merge( $image_meta['sizes'], $created_sizes );
+			unset( $image_meta['subsize_errors'] );
+			wp_update_attachment_metadata( $attachment_id, $image_meta );
+		}
 	}
 
 	return $image_meta;
@@ -317,7 +378,7 @@
 
 	if ( preg_match( '!^image/!', $mime_type ) && file_is_displayable_image( $file ) ) {
 		// Make thumbnails and other intermediate sizes.
-		$metadata = wp_create_image_subsizes( $file, $metadata, $attachment_id );
+		$metadata = wp_create_image_subsizes( $file, $attachment_id );
 	} elseif ( wp_attachment_is( 'video', $attachment ) ) {
 		$metadata = wp_read_video_metadata( $file );
 		$support  = current_theme_supports( 'post-thumbnails', 'attachment:video' ) || post_type_supports( 'attachment:video', 'thumbnail' );
Index: src/wp-includes/post.php
===================================================================
--- src/wp-includes/post.php	(revision 45895)
+++ src/wp-includes/post.php	(working copy)
@@ -5574,6 +5574,7 @@
 		// Don't delete the thumb if another attachment uses it.
 		if ( ! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id ) ) ) {
 			$thumbfile = str_replace( wp_basename( $file ), $meta['thumb'], $file );
+
 			if ( ! empty( $thumbfile ) ) {
 				$thumbfile = path_join( $uploadpath['basedir'], $thumbfile );
 				$thumbdir  = path_join( $uploadpath['basedir'], dirname( $file ) );
@@ -5588,8 +5589,10 @@
 	// Remove intermediate and backup images if there are any.
 	if ( isset( $meta['sizes'] ) && is_array( $meta['sizes'] ) ) {
 		$intermediate_dir = path_join( $uploadpath['basedir'], dirname( $file ) );
+
 		foreach ( $meta['sizes'] as $size => $sizeinfo ) {
 			$intermediate_file = str_replace( wp_basename( $file ), $sizeinfo['file'], $file );
+
 			if ( ! empty( $intermediate_file ) ) {
 				$intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file );
 
@@ -5600,10 +5603,28 @@
 		}
 	}
 
+	if ( ! empty( $meta['original_image'] ) ) {
+		if ( empty( $intermediate_dir ) ) {
+			$intermediate_dir = path_join( $uploadpath['basedir'], dirname( $file ) );
+		}
+
+		$original_image = str_replace( wp_basename( $file ), $meta['original_image'], $file );
+
+		if ( ! empty( $original_image ) ) {
+			$original_image = path_join( $uploadpath['basedir'], $original_image );
+
+			if ( ! wp_delete_file_from_directory( $original_image, $intermediate_dir ) ) {
+				$deleted = false;
+			}
+		}
+	}
+
 	if ( is_array( $backup_sizes ) ) {
 		$del_dir = path_join( $uploadpath['basedir'], dirname( $meta['file'] ) );
+
 		foreach ( $backup_sizes as $size ) {
 			$del_file = path_join( dirname( $meta['file'] ), $size['file'] );
+
 			if ( ! empty( $del_file ) ) {
 				$del_file = path_join( $uploadpath['basedir'], $del_file );
 
@@ -5874,6 +5895,85 @@
 }
 
 /**
+ * Retrieves the path to an uploaded image.
+ *
+ * Similar to `get_attached_file()` however some images may have been
+ * processed after uploading. In this case this function returns the path
+ * to the originally uploaded image file.
+ *
+ * @since 5.3.0
+ *
+ * @param int $attachment_id Attachment ID.
+ * @return string|false Path to the original image file or false if the attachment is not an image.
+ */
+function wp_get_original_attachment_image( $attachment_id ) {
+	if ( ! wp_attachment_is_image( $attachment_id ) ) {
+		return false;
+	}
+
+	$image_meta = wp_get_attachment_metadata( $attachment_id );
+	$image_file = get_attached_file( $attachment_id );
+
+	if ( empty( $image_meta['original_image'] ) ) {
+		$original_image = $image_file;
+	} else {
+		$original_image = path_join( dirname( $image_file ), $image_meta['original_image'] );
+	}
+
+	/**
+	 * Filters the path to the original attachment image.
+	 *
+	 * @since 5.3.0
+	 *
+	 * @param string $original_image Path to original image file.
+	 * @param int    $attachment_id  Attachment ID.
+	 */
+	return apply_filters( 'wp_get_original_attachment_image', $original_image, $attachment_id );
+}
+
+/**
+ * Retrieve the URL to an original attachment image.
+ *
+ * Similar to `wp_get_attachment_url()` however some images may have been
+ * processed after uploading. In this case this function returns the URL
+ * to the originally uploaded image file.
+ *
+ * @since 5.3.0
+ *
+ * @param int $attachment_id Attachment post ID.
+ * @return string|false Attachment image URL, false on error or if the attachment is not an image.
+ */
+function wp_get_original_attachment_image_url( $attachment_id ) {
+	if ( ! wp_attachment_is_image( $attachment_id ) ) {
+		return false;
+	}
+
+	$image_url = wp_get_attachment_url( $attachment_id );
+
+	if ( empty( $image_url ) ) {
+		return false;
+	}
+
+	$image_meta = wp_get_attachment_metadata( $attachment_id );
+
+	if ( empty( $image_meta['original_image'] ) ) {
+		$original_image_url = $image_url;
+	} else {
+		$original_image_url = path_join( dirname( $image_url ), $image_meta['original_image'] );
+	}
+
+	/**
+	 * Filters the URL to the original attachment image.
+	 *
+	 * @since 5.3.0
+	 *
+	 * @param string $original_image_url URL to original image.
+	 * @param int    $attachment_id      Attachment ID.
+	 */
+	return apply_filters( 'wp_get_original_attachment_image_url', $original_image_url, $attachment_id );
+}
+
+/**
  * Verifies an attachment is of a given type.
  *
  * @since 4.2.0
