I am trying to use the_post_thumbnail to display some thumbnail images on one of our pages.
I have set
<? the_post_thumbnail(array(291,167)); ?>
However when I upload the images, they are all getting weird sizes.
Some show up as 291x160, some 280x140 and other weird sizes.
Is there any way to have the_post_thumbnail size the images the exact same size regardless of their original size?
Alternatively, Is there a way for WP to crop them to that size instead of trying to shrink fit?
Caroline Keim answers:
Make sure in your functions.php you have this -
add_theme_support( 'post-thumbnails' );
add_image_size( 'single-post-thumbnail', 291, 168, true );
Then in your template do this -
<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>
Then you can use this plugin to regenerate your thumbnails.
http://wordpress.org/extend/plugins/regenerate-thumbnails/
Dan | gteh comments:
Thank you.
this solved my issue.
I was trying to pass the 'true' for crop in the_post_thumbnail but I guess it has to be done in functions via add_image_size.
Didn't know I had to re-generate the thumbnails either. Figured it set the size of the thumbnail at load-time based on the values being passed.
Dan | gteh comments:
There seems to be a problem on wpquestions. I can't assign prize money right now, the server is throwing a 500 internal server error. I will take care of it soon.
Thanks again.
Caroline Keim comments:
Thanks gteh!
Glad you figured it out. Yeah, I've found you always need to regenerate thumbnails for older posts otherwise it just effects posts from then on out.
Nilesh shiragave answers:
which theme you are using. check your themes functions.php file to check whether default thumbnail size is added using following function
set_post_thumbnail_size( ); // default Post Thumbnail dimensions
for more details of this function check
http://codex.wordpress.org/Function_Reference/set_post_thumbnail_size
or
for more details of this function check
<?php add_image_size( $name, $width, $height, $crop ); ?>
http://codex.wordpress.org/Function_Reference/add_image_size
Marko Nikolic answers:
Hi,
take a look at this video: [[LINK href="http://www.youtube.com/watch?v=SNSoqzRA_IY"]]Crop[[/LINK]]
You can use it to crop images to exact size you need.