WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/07/2019 01:33:16 AM (6 weeks ago)
Author:
azaozz
Message:

Media: Improve handling of cases where an uploaded image matches exactly a defined intermediate size. In most of these cases the original image has been edited by the user and is "web ready", there is no need for an identical intermediate image.

Introduces the wp_image_resize_identical_dimensions filter so plugins and themes can determine whether a new image with identical dimensions should be created, defaults to false.

Props wpdennis, HKandulla, galbaras, azaozz.
See #32437.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/dimensions.php

    r42343 r46077  
    132132        // crop 640x480 to fit 640x480 (no change)
    133133        $out = image_resize_dimensions( 640, 480, 640, 480, true );
     134        $this->assertFalse( $out );
     135
     136        // resize 640x480 to fit 640x480 (no change)
     137        $out = image_resize_dimensions( 640, 480, 640, 480, false );
     138        $this->assertFalse( $out );
     139
     140        // Test with the filter override.
     141        add_filter( 'wp_image_resize_identical_dimensions', '__return_true' );
     142
     143        // crop 640x480 to fit 640x480 (no change)
     144        $out = image_resize_dimensions( 640, 480, 640, 480, true );
    134145        // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
    135146        $this->assertEquals( array( 0, 0, 0, 0, 640, 480, 640, 480 ), $out );
     
    139150        // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h
    140151        $this->assertEquals( array( 0, 0, 0, 0, 640, 480, 640, 480 ), $out );
     152
     153        remove_filter( 'wp_image_resize_identical_dimensions', '__return_true' );
    141154    }
    142155
Note: See TracChangeset for help on using the changeset viewer.