diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php index a5642608fb..6150b99b82 100644 --- a/src/wp-includes/media.php +++ b/src/wp-includes/media.php @@ -503,8 +503,9 @@ function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = fal } // if the resulting image would be the same size or larger we don't want to resize it - if ( $new_w >= $orig_w && $new_h >= $orig_h ) + if ( $new_w >= $orig_w && $new_h >= $orig_h && $dest_w != $orig_w && $dest_h != $orig_h ) { return false; + } // the return array matches the parameters to imagecopyresampled() // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h diff --git a/tests/phpunit/tests/image/dimensions.php b/tests/phpunit/tests/image/dimensions.php index 20f2cf4626..79a7f0e575 100644 --- a/tests/phpunit/tests/image/dimensions.php +++ b/tests/phpunit/tests/image/dimensions.php @@ -128,6 +128,18 @@ class Tests_Image_Dimensions extends WP_UnitTestCase { $this->assertEquals( array(0, 0, 0, 20, 400, 500, 480, 600), $out ); } + function test_640x480() { + // crop 640x480 to fit 640x480 (no change) + $out = image_resize_dimensions(640, 480, 640, 480, true); + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + $this->assertEquals( array(0, 0, 0, 0, 640, 480, 640, 480), $out ); + + // resize 640x480 to fit 640x480 (no change) + $out = image_resize_dimensions(640, 480, 640, 480, false); + // dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h + $this->assertEquals( array(0, 0, 0, 0, 640, 480, 640, 480), $out ); + } + /** * @ticket 19393 */