WordPress.org

Make WordPress Core

Changeset 35524


Ignore:
Timestamp:
11/04/2015 09:43:44 PM (4 years ago)
Author:
azaozz
Message:

Responsive images: do not generate srcset for GIFs that are inserted at full size. Prevents breaking animated GIFs.

Props joemcgill.
Fixes #34528.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/media.php

    r35498 r35524  
    981981    // Bail early if error/no width.
    982982    if ( $image_width < 1 ) {
     983        return false;
     984    }
     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
    983990        return false;
    984991    }
  • trunk/tests/phpunit/tests/media.php

    r35498 r35524  
    964964        $this->assertSame( $image_html, wp_make_content_images_responsive( $image_html ) );
    965965    }
     966
     967    /**
     968     * @ticket 33641
     969     * @ticket 34528
     970     */
     971    function test_wp_calculate_image_srcset_animated_gifs() {
     972        // Mock meta for an animated gif.
     973        $image_meta = array(
     974            'width' => 1200,
     975            'height' => 600,
     976            'file' => 'animated.gif',
     977            'sizes' => array(
     978                'thumbnail' => array(
     979                    'file' => 'animated-150x150.gif',
     980                    'width' => 150,
     981                    'height' => 150,
     982                    'mime-type' => 'image/gif'
     983                ),
     984                'medium' => array(
     985                    'file' => 'animated-300x150.gif',
     986                    'width' => 300,
     987                    'height' => 150,
     988                    'mime-type' => 'image/gif'
     989                ),
     990                'large' => array(
     991                    'file' => 'animated-1024x512.gif',
     992                    'width' => 1024,
     993                    'height' => 512,
     994                    'mime-type' => 'image/gif'
     995                ),
     996            )
     997        );
     998
     999        $image_src = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_meta['file'];
     1000        // Test with soft resized size array.
     1001        $size_array = array(900, 450);
     1002
     1003        $this->assertFalse( wp_calculate_image_srcset( $image_src, $size_array, $image_meta ) );
     1004    }
    9661005}
Note: See TracChangeset for help on using the changeset viewer.