Variable image aspect ratio crop in WordPress

Posted in wordpress

To crop an image with a variable width/height, use ‘auto’ instead of pixels.  Here is the code to add to functions.php

if ( function_exists( ‘add_image_size’ ) ) add_theme_support( ‘post-thumbnails’ );
if ( function_exists( ‘add_image_size’ ) ) {
add_image_size( ‘home-thumb’, 100, 100, true );
add_image_size( ‘featured’, 268, ‘auto’, true );
}