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 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

share|improve this question
    
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 '11 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 '11 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 '11 at 7:13
add comment

3 Answers

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:

the_post_thumbnail('my_thumb');
share|improve this answer
add comment

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.

share|improve this answer
add comment

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 ):

share|improve this answer
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.