diff --git src/wp-includes/media.php src/wp-includes/media.php
index 562f283..0a5c97c 100644
|
|
function wp_calculate_image_srcset( $image_src, $size_array, $image_meta, $attac |
983 | 983 | return false; |
984 | 984 | } |
985 | 985 | |
986 | | // Don't add srcset attributes to (animated) gifs that are inserted at full size. |
987 | | if ( isset( $image_sizes['thumbnail']['mime-type'] ) && 'image/gif' === $image_sizes['thumbnail']['mime-type'] && |
988 | | false !== strpos( $image_src, $image_meta['file'] ) ) { |
989 | | |
990 | | return false; |
991 | | } |
992 | | |
993 | 986 | $image_basename = wp_basename( $image_meta['file'] ); |
994 | 987 | $image_baseurl = _wp_upload_dir_baseurl(); |
995 | 988 | |
996 | | // Add full size to the '$image_sizes' array. |
997 | | $image_sizes['full'] = array( |
998 | | 'width' => $image_meta['width'], |
999 | | 'height' => $image_meta['height'], |
1000 | | 'file' => $image_basename, |
1001 | | ); |
| 989 | /* |
| 990 | * Animated GIFs are a special case since only full size animated GIF files include animation. |
| 991 | * If the original file is a GIF and is the full size, we won't include a 'srcset' attribute. |
| 992 | * However, if the original file is a GIF and is an intermediate size, we exclude the 'full' size |
| 993 | * in the 'srcset' list so it doesn't become animated. |
| 994 | */ |
| 995 | if ( isset( $image_sizes['thumbnail']['mime-type'] ) && 'image/gif' === $image_sizes['thumbnail']['mime-type'] ) { |
| 996 | if ( strpos( $image_src, $image_meta['file'] ) ) { |
| 997 | return false; |
| 998 | } |
| 999 | } else { |
| 1000 | $image_sizes['full'] = array( |
| 1001 | 'width' => $image_meta['width'], |
| 1002 | 'height' => $image_meta['height'], |
| 1003 | 'file' => $image_basename, |
| 1004 | ); |
| 1005 | } |
1002 | 1006 | |
1003 | 1007 | // Uploads are (or have been) in year/month sub-directories. |
1004 | 1008 | if ( $image_basename !== $image_meta['file'] ) { |
diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php
index 5734f3e..d3e89d2 100644
|
|
EOF; |
996 | 996 | ) |
997 | 997 | ); |
998 | 998 | |
999 | | $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['file']; |
| 999 | $full_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['file']; |
| 1000 | $large_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['sizes']['large']['file']; |
| 1001 | |
1000 | 1002 | // Test with soft resized size array. |
1001 | 1003 | $size_array = array(900, 450); |
1002 | 1004 | |
1003 | | $this->assertFalse( wp_calculate_image_srcset( $image_src, $size_array, $image_meta ) ); |
| 1005 | // Full size GIFs should not return a 'srcset'. |
| 1006 | $this->assertFalse( wp_calculate_image_srcset( $full_src, $size_array, $image_meta ) ); |
| 1007 | // Intermediate sized GIFs should not include the full size in the 'srcset'. |
| 1008 | $this->assertFalse( strpos( wp_calculate_image_srcset( $large_src, $size_array, $image_meta ), $full_src ) ); |
1004 | 1009 | } |
1005 | 1010 | } |