From b59b9f466acd237908e4a5d9f78e988e096cafd6 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sun, 30 Nov 2014 06:26:26 +0000 Subject: [PATCH] Fix edge-case in media cropping where selection and destination are the same size. Adds unit tests. Props mboynes. Fixes #19793. git-svn-id: https://develop.svn.wordpress.org/trunk@30639 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/media.php | 3 ++- tests/phpunit/tests/image/dimensions.php | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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 */