tags:

views:

34

answers:

2

I'm using the post thumbnail feature to show portfolio work, so for example <?php the_post_thumnail(); ?> the problem is I want to show a particular width of image only, which is 640 but because my pieces are website they have varying heights.

I'm using this code to create the images: add_image_size( '640', 480 ,true ); but it's specifying the height how can I ONLY specify the width??

Thanks

Ps. I know I could use CSS, but I want to actually create images at 640 wide and not use any timthumb stuff either. Thanks

+1  A: 

You can calculate the ratio height from width. NewHeight = Height * NewWidth / Width;

Ex: OldSize(400, 300)
    NewSize(NewHeight, 640)
    NewHeight = 400*640/300
              = 853
stackunderflow
Sorry I don't understand. Can you show an example?
Cameron
Added an example
stackunderflow
+1  A: 

You can use add_image_size to define sizes that require one dimension and that will proportionally scale the other:

add_image_size('width-640', 640, 0, false);
add_image_size('height-640', 0, 640, false);

You can also achieve this with one line

add_image_size('constrain-640', 640, 640, false);

This will proportionally crop an image so that its longest side is no larger than 640px.

Gipetto