[wp-trac] [WordPress Trac] #38906: wp_get_attachment_image_src() sometimes gives incorrect width and height values
WordPress Trac
noreply at wordpress.org
Tue Nov 22 18:57:35 UTC 2016
#38906: wp_get_attachment_image_src() sometimes gives incorrect width and height
values
----------------------------+-----------------------------
Reporter: pressupinc | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Media | Version: trunk
Severity: normal | Keywords:
Focuses: administration |
----------------------------+-----------------------------
The following is an example of a problem that happens to me regularly
across multiple sites.
I have an image size registered as follows:
{{{#!php
add_image_size( 'featured-home', 1600, 600, true ); // width, height, crop
}}}
When I run wp_get_attachment_image_src() as follows:
{{{#!php
$image = wp_get_attachment_image_src( $post_id, 'featured-home' );
}}}
...and then print_r() the result, I get this:
{{{#!php
Array
(
[0] => http://localhost:8080/lacoastalservices/wp-
content/uploads/2016/09/wetlands-1600x600.jpg
[1] => 1080
[2] => 405
[3] => 1
)
}}}
The image itself is actually 1600 by 600 pixels wide, but for some reason
the width and height values given in the array are "scaled down" to the
width of the next largest image size on the site (1080px), and the
corresponding image height if it were actually that wide (405px).
Note that WordPress's "large" default image size is still at its default
of 1024px, so I don't think that's the problem.
You can hopefully reproduce this by running the "Display All Image Sizes"
plugin on a few sites and looking for images whose larger image sizes have
a mismatch between their identified dimensions and their actual urls.
"Display All Image Sizes" is using wp_get_attachment_image_src() to
generate the text strings that describe image sizes, which is how I became
aware of this bug.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38906>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list