Custom cropped WordPress thumbnails, overwritten when using crop in the media library

I defined custom thumbnail sizes in my functions.php file using this function:

add_theme_support( 'post-thumbnails' );
if ( function_exists( 'add_image_size' ) ) { 
add_image_size( 'address', 960, 250, true );
}

Which works fine as long as I don’t use the ‘Edit Image’ function (crop tool) in the WordPress back-end, after uploading my image. When I do so, the height that I defined (250px) is not considered anymore.

Read More

Has anyone else encountered this problem and knows how to solve it?

Related posts

Leave a Reply

2 comments

  1. It is a known problem. I’ve read somewhere that it will be solved in one of the upcoming releases. Until then you can use the following code in your functions.php. Just adjust the image sizes.

    if (function_exists('add_image_size')) {
        add_image_size( 'dummy-1', 940, 450, true );
        add_image_size( 'dummy-2', 480, 0 );
    }
    
    global $_wp_additional_image_sizes;
    foreach ( $_wp_additional_image_sizes as $name => $image_size ){
        update_option( $name."_size_w", $image_size['width'] );
        update_option( $name."_size_h", $image_size['height'] );
        update_option( $name."_crop", $image_size['crop'] );
    }
    
    add_filter( 'intermediate_image_sizes', 'regenerate_custom_image_sizes' );
    function regenerate_custom_image_sizes( $sizes ){
        global $_wp_additional_image_sizes;
        foreach ( $_wp_additional_image_sizes as $name => $size ){
            $sizes[] = $name;
        }
        return $sizes;
    } 
    
  2. The ‘Edit Image’ function is considering only the original file (‘full’) image for cropping , resize, rotate and other minor “editing” . you have an option there to specify if you want it for all sizes, only thumbnails, or all sizes except thumbnails..