Opened 5 years ago
Last modified 5 years ago
#49640 new defect (bug)
image_get_intermediate_size returns wrong
Reported by: | CHEWX | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | |
Component: | Media | Keywords: | |
Focuses: | Cc: |
Description (last modified by )
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:
// 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.
Hi there, welcome back to WordPress Trac! Thanks for the report.
Just adding links to some tickets that might be related: #21714, #34384, #47713.