diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
index a0e7ef9c6c..7fbe889cde 100644
a
|
b
|
function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { |
775 | 775 | } |
776 | 776 | |
777 | 777 | foreach ( $imagedata['sizes'] as $_size => $data ) { |
| 778 | // If the original image matches the required size, use it instead of a generated size and short circuit. |
| 779 | if ( (int) $imagedata['width'] === (int) $size[0] && (int) $imagedata['height'] === (int) $size[1] ) { |
| 780 | $candidates[ $data['width'] * $data['height'] ] = array( |
| 781 | 'width' => $imagedata['width'], |
| 782 | 'height' => $imagedata['height'], |
| 783 | 'file' => wp_basename( $imagedata['file'] ), |
| 784 | ); |
| 785 | break; |
| 786 | } |
| 787 | |
778 | 788 | // If there's an exact match to an existing image size, short circuit. |
779 | 789 | if ( (int) $data['width'] === (int) $size[0] && (int) $data['height'] === (int) $size[1] ) { |
780 | 790 | $candidates[ $data['width'] * $data['height'] ] = $data; |
… |
… |
function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { |
817 | 827 | // Constrain the width and height attributes to the requested values. |
818 | 828 | list( $data['width'], $data['height'] ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size ); |
819 | 829 | |
| 830 | } elseif ( (int) $imagedata['width'] === $imagedata['sizes'][ $size ]['width'] && (int) $imagedata['height'] === $imagedata['sizes'][ $size ]['height'] ) { |
| 831 | $data = array( |
| 832 | 'width' => $imagedata['width'], |
| 833 | 'height' => $imagedata['height'], |
| 834 | 'file' => wp_basename( $imagedata['file'] ), |
| 835 | ); |
820 | 836 | } elseif ( ! empty( $imagedata['sizes'][ $size ] ) ) { |
821 | 837 | $data = $imagedata['sizes'][ $size ]; |
822 | 838 | } |
diff --git a/tests/phpunit/data/images/test_100x200.png b/tests/phpunit/data/images/test_100x200.png
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/phpunit/data/images/test_500x500.png b/tests/phpunit/data/images/test_500x500.png
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/phpunit/tests/image/intermediateSize.php b/tests/phpunit/tests/image/intermediateSize.php
index 830359427a..fc2f9d6088 100644
a
|
b
|
class Tests_Image_Intermediate_Size extends WP_UnitTestCase { |
15 | 15 | parent::tear_down(); |
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 { |
88 | 88 | } |
89 | 89 | } |
90 | 90 | |
| 91 | /** |
| 92 | * @ticket 50866 |
| 93 | * @ticket 47713 |
| 94 | */ |
| 95 | function test_get_intermediate_size_with_same_as_original_size() { |
| 96 | add_image_size( 'test-size', 100, 200, true ); |
| 97 | |
| 98 | $file = DIR_TESTDATA . '/images/test_100x200.png'; |
| 99 | $id = $this->_make_attachment( $file, 0 ); |
| 100 | |
| 101 | // Look for a size by name. |
| 102 | $image = image_get_intermediate_size( $id, 'test-size' ); |
| 103 | |
| 104 | // Test that WordPress returns the original image path and not an intermediate size |
| 105 | $this->assertSame( |
| 106 | $image['file'], |
| 107 | 'test_100x200.png', |
| 108 | 'did not return original before removing image size' |
| 109 | ); |
| 110 | |
| 111 | $image = image_get_intermediate_size( $id, [100, 200] ); |
| 112 | |
| 113 | // Cleanup. |
| 114 | remove_image_size( 'test-size' ); |
| 115 | |
| 116 | // Test that WordPress returns the original image path and not an intermediate size |
| 117 | $this->assertSame( |
| 118 | $image['file'], |
| 119 | 'test_100x200.png', |
| 120 | 'did not return original after removing image size' |
| 121 | ); |
| 122 | } |
| 123 | |
91 | 124 | /** |
92 | 125 | * @ticket 17626 |
93 | 126 | * @requires function imagejpeg |