image_get_intermediate_size() may return wrong thumbnail size
|Reported by:||chipbennett||Owned by:||markoheijnen|
See this WPSE question for a more detailed explanation of the problem.
Essentially, if get_the_post_thumbnail() is passed an array for the $size argument, and if two images have one dimension exactly the same, the image with the smaller opposing dimension will be returned, even if the dimensions for the other image are declared explicitly.
The issue appears to be due to the way that image_get_intermediate_size() determines if an image exists that is cropped to dimensions similar to the specified $size array. As soon as it finds one, it uses it.
I've attached a patch that first attempts to find an image cropped exactly on both dimensions, before looking for images cropped exactly only on one dimension. There will still be edge cases where the wrong image might be returned, but I'm not sure of the most efficient way to handle such cases.
(Note: props to Rarst for finding the underlying issue.)
Change History (24)
comment:14 nacin — 20 months ago
- Owner set to nacin
- Resolution set to fixed
- Status changed from new to closed
comment:15 nacin — 20 months ago
- Milestone changed from 3.4 to Future Release
- Resolution fixed deleted
- Status changed from closed to reopened
comment:20 markoheijnen — 6 weeks ago
- Milestone changed from Future Release to 3.8
- Owner changed from nacin to markoheijnen
- Status changed from reopened to assigned