1

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

2

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.

  • 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
  • +1 for the mentioning regenerate your thumbnails. – Floris Sep 6 '18 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.