Index: src/wp-includes/media.php
===================================================================
--- src/wp-includes/media.php	(revision 35465)
+++ src/wp-includes/media.php	(working copy)
@@ -814,11 +814,12 @@
 		// Generate 'srcset' and 'sizes' if not already present.
 		if ( empty( $attr['srcset'] ) ) {
 			$image_meta = wp_get_attachment_metadata( $attachment_id );
+			$size_name = is_string( $size ) ? $size : '';
 
 			if ( is_array( $image_meta ) ) {
 				$size_array = array( absint( $width ), absint( $height ) );
 				$srcset = wp_calculate_image_srcset( $src, $size_array, $image_meta, $attachment_id );
-				$sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id );
+				$sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id, $size_name );
 
 				if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) {
 					$attr['srcset'] = $srcset;
@@ -1082,10 +1083,10 @@
  * @param array        $image_meta    Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
  * @param int          $attachment_id Optional. Image attachment ID. Either `$image_meta` or `$attachment_id` is needed
  *                                    when using the image size name as argument for `$size`.
- *
+ * @param string       $size_name     Optional. The image size name (thumbnail, medium, large, etc.).
  * @return string|bool A valid source size value for use in a 'sizes' attribute or false.
  */
-function wp_get_attachment_image_sizes( $size, $image_meta = null, $attachment_id = 0 ) {
+function wp_get_attachment_image_sizes( $size, $image_meta = null, $attachment_id = 0, $size_name = '' ) {
 	$width = 0;
 
 	if ( is_numeric( $size ) ) {
@@ -1093,6 +1094,8 @@
 	} elseif ( is_array( $size ) ) {
 		$width = absint( $size[0] );
 	} elseif ( is_string( $size ) ) {
+		$size_name = $size;
+
 		if ( ! $image_meta && $attachment_id ) {
 			$image_meta = wp_get_attachment_metadata( $attachment_id );
 		}
@@ -1123,7 +1126,7 @@
 	 * @param array        $image_meta    The image meta data as returned by 'wp_get_attachment_metadata()'.
 	 * @param int          $attachment_id Image attachment ID of the original image.
 	 */
-	return apply_filters( 'wp_get_attachment_image_sizes', $sizes, $size, $image_meta, $attachment_id );
+	return apply_filters( 'wp_get_attachment_image_sizes', $sizes, $size, $image_meta, $attachment_id, $size_name );
 }
 
 /**
@@ -1235,11 +1238,17 @@
 		return $image;
 	}
 
+	$size_name = '';
+
+	if ( strpos( $image, 'size-' ) !== false && preg_match( '/ class="([^"]+)"/', $image, $classes ) ) {
+		$size_name = preg_match( '/(size-[^ ]+)/', $classes[1], $match_size_name ) ? $match_size_name[1] : '';
+	}
+
 	$size_array = array( $width, $height );
 	$srcset = wp_calculate_image_srcset( $src, $size_array, $image_meta, $attachment_id );
 
 	if ( $srcset ) {
-		$sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id );
+		$sizes = wp_get_attachment_image_sizes( $size_array, $image_meta, $attachment_id, $size_name );
 	}
 
 	if ( $srcset && $sizes ) {
