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
This commit is contained in:
Scott Taylor 2014-11-30 06:26:26 +00:00
parent ac2c986831
commit b59b9f466a
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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
*/