From 72a1124c451a7dc46f182612989276c4fbc8007a Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sat, 7 Nov 2015 02:10:25 +0000 Subject: [PATCH] Responsive images: omit full size images from srcset attributes when the original file is an intermediate sized GIF so we don't accidentally add animation to an otherwise flat image. Update the tests to cover this case. Props joemcgill, H-Shredder, SergeyBiryukov. Fixes #34528. Built from https://develop.svn.wordpress.org/trunk@35561 git-svn-id: http://core.svn.wordpress.org/trunk@35525 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 27 ++++++++++++++------------- wp-includes/version.php | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index 562f2834dc..23d813f512 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -983,22 +983,23 @@ function wp_calculate_image_srcset( $image_src, $size_array, $image_meta, $attac return false; } - // Don't add srcset attributes to (animated) gifs that are inserted at full size. - if ( isset( $image_sizes['thumbnail']['mime-type'] ) && 'image/gif' === $image_sizes['thumbnail']['mime-type'] && - false !== strpos( $image_src, $image_meta['file'] ) ) { - - return false; - } - $image_basename = wp_basename( $image_meta['file'] ); $image_baseurl = _wp_upload_dir_baseurl(); - // Add full size to the '$image_sizes' array. - $image_sizes['full'] = array( - 'width' => $image_meta['width'], - 'height' => $image_meta['height'], - 'file' => $image_basename, - ); + /* + * WordPress flattens animated GIFs into one frame when generating intermediate sizes. + * To avoid hiding animation in user content, if src is a full size GIF, a srcset attribute is not generated. + * If src is an intermediate size GIF, the full size is excluded from srcset to keep a flattened GIF from becoming animated. + */ + if ( ! isset( $image_sizes['thumbnail']['mime-type'] ) || 'image/gif' !== $image_sizes['thumbnail']['mime-type'] ) { + $image_sizes['full'] = array( + 'width' => $image_meta['width'], + 'height' => $image_meta['height'], + 'file' => $image_basename, + ); + } elseif ( strpos( $image_src, $image_meta['file'] ) ) { + return false; + } // Uploads are (or have been) in year/month sub-directories. if ( $image_basename !== $image_meta['file'] ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 8cd15ea3c3..c9751f14d5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-beta3-35560'; +$wp_version = '4.4-beta3-35561'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.