I m having trouble in resizing media images. I tried add_image_size function to resize my original image like below.

add_image_size( 'my_thumb', 145, 100);

it creates thumb images with height 100 but it changes width for every image. like some image 66x100,140X100 .How to make sure the width 145

Sorry could n't share links and screenshot due to low reputation

I tried also timthumb. getting same result.Where i'm stucking .

Please help me.

Thanks in advance

  • add_image_size creates an image of specified size when you upload a new image into a gallery. Is that what you exactly want? Or you want to display an image with specified size? Then you need to use the_post_thumbnail( 'your-size' ); in the loop.
    – Alexey
    Sep 28, 2011 at 5:32
  • @Alexey: yes i wanna display an image with specified size.But i couldn't use the_post_thumbnail because its an attachement
    – Elan
    Sep 28, 2011 at 6:05
  • ok. This code checks if post has attached images and display them. There is also possibility to specify your size.
    – Alexey
    Sep 28, 2011 at 7:13

3 Answers 3


If you are trying to retroactively resize images, use the code you've supplied in your functions.php, then run the Regenerate Thumbnails plugin http://wordpress.org/extend/plugins/regenerate-thumbnails/

Once you've done that you should be able to display the image using the following:


You might want to add:

add_image_size( 'my_thumb', 145, 100, true);

Adding true should enable WordPress to do a hard crop to keep your dimensions and not just scale the image. (Provided your images are at least that width and height or larger.)

As mentioned above you would need to regenerate your current images.


First, if you added your add_image_size() call to functions.php after you already uploaded/attached images, you will need to regenerate the thumbnails for those attached images.

Second, you should be able to return/output the image for any defined image size, using wp_get_attachment_image( $attachment_id, $size ):

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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