Make WordPress Core

Opened 13 years ago

Closed 12 years ago

#19118 closed defect (bug) (invalid)

Incorrect WP_Error in image_resize

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

Description

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 13 years ago.
moved the validation to image_resize

Download all attachments as: .zip

Change History (9)

@mzaweb
13 years ago

moved the validation to image_resize

#1 @mzaweb
13 years ago

  • Version changed from 3.2.1 to 3.3

#2 follow-up: @SergeyBiryukovCore Committer
13 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.

#3 @prockrammer
13 years ago

  • Version changed from 3.2.1 to 3.3.1

This defect exists on 3.3.1 too. Please add the patch

#4 in reply to: ↑ 2 @helenyhou
13 years ago

  • Version changed from 3.3.1 to 3.2.1

SergeyBiryukov:

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

#6 @misterbisson
13 years ago

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

#7 @markoheijnen
12 years 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.

#8 @markoheijnen
12 years 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.