Opened 10 years ago
Last modified 6 years ago
#29370 new defect (bug)
wp_get_attachment_image() returning unexpected image size
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.9.2 |
Component: | Media | Keywords: | |
Focuses: | Cc: |
Description
I have a 'thumbnail' size image of 150x150 px and a 'thumb-250' size image of 166x250 px.
add_image_size('thumb-250', 0, 250, false);
I am using wp_get_attachment_image() to get the best image fit for a 133x200 format.
wp_get_attachment_image( $id, array(133,200) );
this returns the 'thumbnail' size which has an area that's smaller than the requested size, as well as a different aspect ratio. I would expect the 'thumb-250' size image to be returned, which has a bigger area and the exact aspect ratio that was requested.
I tracked this down to the first condition in the following line:
https://core.trac.wordpress.org/browser/tags/3.9.2/src/wp-includes/media.php#L599
Why is the 'thumbnail' image size preferred in the selection process? This means the thumbnail is always returned if it's next in row even if it's area is smaller and the aspect ratio is off.
this persists to wordpress 4.1:
https://core.trac.wordpress.org/browser/tags/4.1/src/wp-includes/media.php#L609
which should be, imho: