WordPress Post Thumbnail

I use the message sketch function to show work with a portfolio, therefore, for example, <?php the_post_thumnail(); ?> <?php the_post_thumnail(); ?> problem is that I want to show only a certain width of the image, which is 640, but because my objects on the site have different heights.

I use this code to create images: add_image_size( '640', 480 ,true ); but it determines the height, how can I ONLY indicate the width

thanks

Ps. I know that I can use CSS, but I want to actually create images at a width of 640 and not use any time material. Thanks

+4
source share
2 answers

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

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

You can also achieve this with a single line

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

This cuts the image proportionally so that its longest side does not exceed 640 pixels.

+4
source

You can calculate the height of the relationship in width. NewHeight = Height * NewWidth / Width;

 Ex: OldSize(400, 300) NewSize(NewHeight, 640) NewHeight = 400*640/300 = 853 
+1
source

All Articles