Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm have a problem with the wp_get_attachment_image_src function returning the incorrect url for an image.

My code looks like this:

$image_main_ar = wp_get_attachment_image_src( $image_ID, 'product_image_main' );

product_image_main is a registered image size:

add_image_size( 'product_image_main', 334, 385, false );

but when I print the $image_main_ar array I get:

Array ( [0] => http://www.website.com/wp-content/uploads/2011/07/Screen-shot-2011-07-27-at-15.03.07.png [1] => 334 [2] => 226 [3] => )

which shows the url for the original image I uploaded, not the resized version, and I've checked the resized version is in the upload folder, and the dimension in the array are correct for the resized version.

The weird thing is the fourth key in the array [3] is empty, but on the images where it returns the correct url it is set to '1'. I've looked in the docs but can't find anything about this fourth value.

Does anyone have any ideas?

Many thanks for any advice.

share|improve this question
1  
if you set add_image size after images where uploaded, it doesn't resize images automatically, try with new image –  Mamaduka Aug 4 '11 at 8:10
    
Does wp_get_attachment_image_src work with other, built in sizes? Are you called add_image_size on its own? Or hooked into something like after_setup_theme? –  chrisguitarguy Sep 2 '11 at 0:10
add comment

2 Answers 2

Try using the Regenerate Thumbnails plugin, that will run through all your media and regenerate thumbnails according to the registered image sizes. Also note that that you're getting the hight parameter as 226 because during add_image_size your third parameter said to not crop the image. Change that to true if you need cropping.

share|improve this answer
1  
Yep I've used a regenerator plugin, and checked that the resized version is in the folder, you'd think that if it was able to return the dimensions of the resized image it would return the url of the resized image! –  peter.shep Aug 4 '11 at 14:29
add comment

I had the same problem, you can see there is thread about it here:

http://wordpress.org/support/topic/plugin-regenerate-thumbnails-broken-badly

This has to do with the fact that the attachment meta is not updated correctly. Basically if you look at your database (post meta) you will find that medium and large and thumnail sizes are explicitly defined, but the custom sizes are missing.

Not sure if you the newest wordpress + the newest regenerate thumbnails hard fixed the issue yet though.

share|improve this answer
1  
Comment it if its not a answer –  Mohit Bumb Oct 5 '11 at 13:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.