Custom Image Sizes
Resizing without cropping is already part of the core functionality, via add_image_size()
.
Note the last parameter:
<?php add_image_size( $name, $width, $height, $crop ); ?>
The Codex entry describes the $crop
parameter as follows:
$crop
(boolean) (optional) Crop the image or not. False - Soft proportional crop mode ; True - Hard crop mode.
Default: false
I prefer to describe the option as hard-crop vs. box-resize. Hard-crop will crop the image based on the most-restrained dimension, whereas box-resize will simply resize the image, retaining its original dimension proportions.
So, to create a box-resized image size, simply define it as follows:
add_image_size( 'image-size-name', $width, $height, false );
Note that this behavior is the default setting. In order to hard-crop, you have to explicitly specify $crop
to be true
.
Post Thumbnails
Changing the post-thumbnail
image size to box-resize is similar; simply use set_post_thumbnail_size()
, which also has a $crop
parameter:
<?php set_post_thumbnail_size( $width, $height, $crop ); ?>
Reserved Image Sizes
I'm pretty sure 'medium'
and 'large'
image sizes are already box-resized rather than hard-cropped.