Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#23860 closed defect (bug) (duplicate)

Custom images sizes not cropped along with default WP image sizes

Reported by: tolgapaksoy Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.3
Component: Media Keywords:
Focuses: Cc:


As of now, when you crop an image in the media page, it doesn't include the custom images sizes. It only crops the full, thumbnail and large variant.

The reason for this is the next line of code in wp-admin/includes/image-edit.php:

$_sizes[ $size ] = array( 'width' => get_option("{$size}_size_w"), 'height' => get_option("{$size}_size_h"), 'crop' => $crop );

It assumes the custom image size properties are also defined in the wp_options table, which they are not.

This is fixed by replacing line 691 and 692 in the image-edit.php with these lines:

$crop = $nocrop ? false : get_option("{$size}_crop");
$size_w = get_option( "{$size}_size_w" );
$size_h = get_option( "{$size}_size_h" );

// No image size metadata found in options table. Force sizes from global images sizes variable
if( ! $crop && ! $size_w && ! $size_h ) {
    global $_wp_additional_image_sizes;

    $crop = $nocrop ? false : $_wp_additional_image_sizes[ $size ]['crop'];
    $size_w = $_wp_additional_image_sizes[ $size ]['width'];
    $size_h = $_wp_additional_image_sizes[ $size ]['height'];

Is this normal, or do I have to also manually add the options into the table? If so, why is this not handled in the add_images_sizes() function?

Change History (1)

#1 @SergeyBiryukov
9 years ago

  • Component changed from Gallery to Media
  • Keywords dev-feedback has-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
  • Version changed from 3.5.1 to 3.3

Duplicate of #19889.

Note: See TracTickets for help on using tickets.