diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
index e1091b9d8e..a1c29ba73f 100644
a
|
b
|
function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { |
777 | 777 | } |
778 | 778 | |
779 | 779 | foreach ( $imagedata['sizes'] as $_size => $data ) { |
| 780 | // If the original image match the required size, use it instead of a generated size and short circuit. |
| 781 | if ( (int) $imagedata['width'] === (int) $size[0] && (int) $imagedata['height'] === (int) $size[1] ) { |
| 782 | $candidates[ $data['width'] * $data['height'] ] = array( |
| 783 | 'width' => $imagedata['width'], |
| 784 | 'height' => $imagedata['height'], |
| 785 | 'file' => wp_basename( $imagedata['file'] ), |
| 786 | ); |
| 787 | break; |
| 788 | } |
| 789 | |
780 | 790 | // If there's an exact match to an existing image size, short circuit. |
781 | | if ( intval( $data['width'] ) === intval( $size[0] ) && intval( $data['height'] ) === intval( $size[1] ) ) { |
| 791 | if ( (int) $data['width'] === (int) $size[0] && (int) $data['height'] === (int) $size[1] ) { |
782 | 792 | $candidates[ $data['width'] * $data['height'] ] = $data; |
783 | 793 | break; |
784 | 794 | } |
… |
… |
function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { |
819 | 829 | // Constrain the width and height attributes to the requested values. |
820 | 830 | list( $data['width'], $data['height'] ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size ); |
821 | 831 | |
| 832 | } elseif ( (int) $imagedata['width'] === $imagedata['sizes'][ $size ]['width'] && (int) $imagedata['height'] === $imagedata['sizes'][ $size ]['height'] ) { |
| 833 | $data = array( |
| 834 | 'width' => $imagedata['width'], |
| 835 | 'height' => $imagedata['height'], |
| 836 | 'file' => wp_basename( $imagedata['file'] ), |
| 837 | ); |
822 | 838 | } elseif ( ! empty( $imagedata['sizes'][ $size ] ) ) { |
823 | 839 | $data = $imagedata['sizes'][ $size ]; |
824 | 840 | } |
diff --git a/tests/phpunit/data/images/test_100x200.png b/tests/phpunit/data/images/test_100x200.png
new file mode 100644
index 0000000000..ed0b6f898d
Binary files /dev/null and b/tests/phpunit/data/images/test_100x200.png differ
diff --git a/tests/phpunit/data/images/test_500x500.png b/tests/phpunit/data/images/test_500x500.png
new file mode 100644
index 0000000000..c0d6e82432
Binary files /dev/null and b/tests/phpunit/data/images/test_500x500.png differ
diff --git a/tests/phpunit/tests/image/intermediateSize.php b/tests/phpunit/tests/image/intermediateSize.php
index c2ac785058..c3561a1ff9 100644
a
|
b
|
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { |
15 | 15 | parent::tearDown(); |
16 | 16 | } |
17 | 17 | |
18 | | public function _make_attachment( $file, $parent_post_id = 0 ) { |
| 18 | public function _make_attachment( $file = '', $parent_post_id = 0 ) { |
19 | 19 | $contents = file_get_contents( $file ); |
20 | 20 | $upload = wp_upload_bits( wp_basename( $file ), null, $contents ); |
21 | 21 | |
… |
… |
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { |
85 | 85 | $this->assertTrue( strpos( $image['file'], '330x220' ) > 0 ); |
86 | 86 | } |
87 | 87 | |
| 88 | /** |
| 89 | * @ticket 50866 |
| 90 | * @ticket 47713 |
| 91 | */ |
| 92 | function test_get_intermediate_size_with_same_as_original_size() { |
| 93 | add_image_size( 'test-size', 100, 200, true ); |
| 94 | |
| 95 | $file = DIR_TESTDATA . '/images/test_100x200.png'; |
| 96 | $id = $this->_make_attachment( $file, 0 ); |
| 97 | |
| 98 | // Look for a size by name. |
| 99 | $image = image_get_intermediate_size( $id, 'test-size' ); |
| 100 | |
| 101 | // Test that WordPress returns the original image path and not an intermediate size |
| 102 | $this->assertSame( $image['file'], 'test_100x200.png' ); |
| 103 | |
| 104 | $image = image_get_intermediate_size( $id, [100, 200] ); |
| 105 | |
| 106 | // Cleanup. |
| 107 | remove_image_size( 'test-size' ); |
| 108 | |
| 109 | // Test that WordPress returns the original image path and not an intermediate size |
| 110 | $this->assertSame( $image['file'], 'test_100x200.png' ); |
| 111 | } |
| 112 | |
88 | 113 | /** |
89 | 114 | * @ticket 17626 |
90 | 115 | */ |