I am using
wp_get_attachment_image_src to construct the
srcset attribute of an
img tag. In that attribute I want to output a comma separated list of image urls along with the image widths.
Using the Media Settings page, I have configured the image sizes to be as follows:
- Thumbnail size: 150x150
- Medium size: 640x480
- Large size: 1024x768
- Small size: 278x320
wp_get_attachment_image_src function returns the correct urls and the correct widths for the image sizes
small is a custom size I added using
If I call
wp_get_attachment_image_src( $image_id, 'large' ), the returned array looks like this:
array ( 0 => 'http://localhost/wp-content/uploads/2014/10/image-1024x768.jpg', 1 => 640, 2 => 480, 3 => true, )
Checking the image which can be found at that url turns up the image with the correct dimensions.
Currently i am using the php builtin function getimagesize to circumvent this problem, but this function call takes significantly longer than simply accessing the index returned by
Without getimagesize (mtime before and after execution):
- '0.83761000 1415195440'
- '0.83831600 1415195440'
- '0.34808000 1415195635'
- '0.35323900 1415195635'
What can I do to make wp_get_attachment_image_src return the correct dimensions?