[wp-trac] [WordPress Trac] #49640: image_get_intermediate_size returns wrong
WordPress Trac
noreply at wordpress.org
Fri Mar 13 10:25:35 UTC 2020
#49640: image_get_intermediate_size returns wrong
--------------------------+-----------------------------
Reporter: CHEWX | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
The function `image_get_intermediate_size` isn't working as expected.
If I upload a `1200px x 900px` image as the original. In WordPress theme I
use `wp_get_attachment_image( $post_id, array( '1x1-large', '1x1-medium' )
);`
`1x1-large` is setup using `add_image_size( '1x1-large', 1024, 1024, true
);`
It will fail as, it cannot create this image size as the the original is
smaller. However, the function in question is clever enough to look for
other aspect ratios that match. This is good.
So if I had another name images called `1x1-medium` (setup using
`add_image_size( '1x1-medium', 768, 768, true );` )
This will exist as the original image is large enough to be sized down to
this.
The function however uses this this code-block to short-circuit it:
https://github.com/WordPress/WordPress/blob/46674e2367b8ca0c15b859bd578bc2119bfa0150
/wp-includes/media.php#L780
```
// If there's an exact match to an existing image size, short circuit.
if ( intval( $data['width'] ) === intval( $size[0] ) && intval(
$data['height'] ) === intval( $size[1] ) ) {
$candidates[ $data['width'] * $data['height'] ] = $data;
break;
}
```
So `$data['width'] =` each image sizes width and `$size[0] = '1x1-large'`
This will never match!!! $size should in theory be a string, not an
integer.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/49640>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list