WordPress.org

Make WordPress Core

Ticket #34528: 34528.4.diff

File 34528.4.diff, 2.6 KB (added by joemcgill, 4 years ago)
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 562f283..008dd64 100644
    function wp_calculate_image_srcset( $image_src, $size_array, $image_meta, $attac 
    983983                return false;
    984984        }
    985985
    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 
    993986        $image_basename = wp_basename( $image_meta['file'] );
    994987        $image_baseurl = _wp_upload_dir_baseurl();
    995988
    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         * WordPress flattens animated GIFs into one frame when generating intermediate sizes.
     991         * To avoid hiding animation in user content, if src is a full size GIF, a srcset attribute is not generated.
     992         * If src is an intermediate size GIF, the full size is excluded from srcset to keep a flattened GIF from becoming animated.
     993         */
     994        if ( ! ( isset( $image_sizes['thumbnail']['mime-type'] ) && 'image/gif' === $image_sizes['thumbnail']['mime-type'] ) ) {
     995                $image_sizes['full'] = array(
     996                        'width'  => $image_meta['width'],
     997                        'height' => $image_meta['height'],
     998                        'file'   => $image_basename,
     999                );
     1000        } elseif ( strpos( $image_src, $image_meta['file'] ) ) {
     1001                return false;
     1002        }
    10021003
    10031004        // Uploads are (or have been) in year/month sub-directories.
    10041005        if ( $image_basename !== $image_meta['file'] ) {
  • tests/phpunit/tests/media.php

    diff --git tests/phpunit/tests/media.php tests/phpunit/tests/media.php
    index 5734f3e..46c04b9 100644
    EOF; 
    996996                        )
    997997                );
    998998
    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
    10001002                // Test with soft resized size array.
    10011003                $size_array = array(900, 450);
    10021004
    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 ) );
    10041009        }
    10051010}