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 trying to display wide image icons from the_post_thumbnail() function. I'm using 'true' value for cropping, but they are not cropped well... I get some strange results with different sizes (I'm trying to use 200width x 150height). If image cannot be display with good proportions (I don't know why whem I'm cropping it? ) then I want it to have exact 150px height always! How can I achieve it? I've been trying with set_post_thumbnail_size() but its even worst...

share|improve this question

1 Answer 1

up vote 1 down vote accepted

If the critical dimension is height, you have a couple options:

Hard-cropping to the exact width/height:

<?php
add_image_size( 'wide-image-icon', 200, 150, true );
?>

The hard-crop will create a thumbnail size using the exact dimensions. Be sure that all images have a minimum width/height as what is defined.

Or soft-cropping (i.e. "box-resizing") constrained to height:

<?php
add_image_size( 'wide-image-icon', 9999, 150, false );
?>

The soft-crop with an unconstrained dimension (i.e. 9999 width) will box-resize to the exact height, while allowing the width to be, essentially, anything. Be sure that all images have a minimum height as what is defined.

Also: make sure that, if you have added these add_image_size() functions after already uploading/attaching some images, that you regenerate your thumbnails.

share|improve this answer
    
Yeah, thats it. Thank you once again Chip ;) –  smogg Jul 28 '11 at 9:09
    
didn't knew there is a valid value soft. Isn't that argument Boolean? –  Sisir Oct 5 '12 at 8:56
    
@sisir that was a typo. Fixed. :) –  Chip Bennett Oct 5 '12 at 19:01

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.