Make WordPress Core

Opened 2 years ago

Closed 13 months ago

#19118 closed defect (bug) (invalid)

Incorrect WP_Error in image_resize

Reported by: mzaweb Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.2.1
Component: Media Keywords:
Focuses: Cc:


image_resize in wp-includes/media.php (line 417)

$dims = image_resize_dimensions($orig_w, $orig_h, $max_w, $max_h, $crop);
if ( !$dims )
    return new WP_Error( 'error_getting_dimensions', __('Could not calculate resized image dimensions') );

But image_resize_dimensions return false if the new dimensions are bigger or equal the old ones, assuming that you won't want to resize the image.

// if the resulting image would be the same size or larger we don't want to resize it
if ( $new_w >= $orig_w && $new_h >= $orig_h )
    return false;

If this is the intended functionality, it shouldn't throw a WP_Error. I think the check for if we want to resize or not should be done in image_resize instead.

Attachments (1)

media.php.patch (1.2 KB) - added by mzaweb 2 years ago.
moved the validation to image_resize

Download all attachments as: .zip

Change History (9)

mzaweb2 years ago

moved the validation to image_resize

comment:1 mzaweb2 years ago

  • Cc mzaweb added
  • Version changed from 3.2.1 to 3.3

comment:2 follow-up: SergeyBiryukov2 years ago

  • Keywords has-patch added
  • Version changed from 3.3 to 3.2.1

Version field indicates the earliest version the bug has been found in, let's keep it at 3.2.1.

comment:3 prockrammer2 years ago

  • Version changed from 3.2.1 to 3.3.1

This defect exists on 3.3.1 too. Please add the patch

comment:4 in reply to: ↑ 2 helenyhou2 years ago

  • Version changed from 3.3.1 to 3.2.1


Version field indicates the earliest version the bug has been found in, let's keep it at 3.2.1.

comment:6 misterbisson21 months ago

Good patch @mzaweb . I'd love to see this in core.

comment:7 markoheijnen19 months ago

  • Keywords close dev-feedback added

The error is intended. You want to resize an image and if that doesn't happend you want an error.
Returning $file implies that the file did got resized.

comment:8 markoheijnen13 months ago

  • Keywords has-patch close dev-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

I'm closing this ticket since my opinion isn't changed on this. Also moving the check from image_resize_dimensions() would allow upscaling when it is used in plugins. Upscale support is fine but it should be consistent.

Also the patch isn't valid anymore since image_resize is deprecated and has been rewritten to use WP_Image_Editor

Note: See TracTickets for help on using tickets.