Thumbnail Cropping with add_image_size?

Refer to the add_image_size() Codex entry:

<?php add_image_size( $name, $width, $height, $crop ); ?>

The $crop parameter is the key:

(boolean) (optional) Crop the image or not. False – Soft proportional crop mode ; True – Hard crop mode.

Default: false

That is:

  • False (default): box-resize – (resize image against the constraining dimension)
  • True: hard-crop – crop the image exactly to the specified dimensions

Thus your code should work:

// Add Theme support
add_theme_support( 'post-thumbnails' );

// Register custom image sizes
add_image_size( 'post-thumb', 620, 207, true );
add_image_size( 'home-thumb', 220, 180, true );
add_image_size( 'index-thumb', 300, 100, true );

If you find that your images are not being rendered/displayed properly, there are a couple of things to verify:

  • For images added prior to implementation of these custom image sizes, you will need to regenerate the thumbnails for those images
  • Image sizes will not be generated for images that are not at least as large as the specified dimensions of a given image size. Thus, ensure that your images are at least as large as your largest-specified hard-crop image size. (Box-resized images are not as constrained, and only need to be at least as large as the smallest dimension of a given image size.)