WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#22438 closed defect (bug) (fixed)

wp_generate_attachment_metadata() should not call WP_Image_Editor if there's nothing to resize

Reported by: mdawaffe Owned by: nacin
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.5
Component: Media Keywords: has-patch
Focuses: Cc:

Description

wp_generate_attachment_metadata() calls WP_Image_Editor::multi_resize() to create the intermediate sizes of the image.

If there are no sizes to create, WP_Image_Editor::get_instance() should not be called. It will not be used for anything and is a waste of resources.

If it is called, and the image is very large, a needless Out of Memory Fatal Error can result.

Patch attached.

Attachments (1)

22438.diff (763 bytes) - added by mdawaffe 8 years ago.

Download all attachments as: .zip

Change History (4)

@mdawaffe
8 years ago

#1 @mdawaffe
8 years ago

I put in the else condition to set $metadata['sizes'] = array() since that's what the current behavior in trunk is: ::multi_resize() returns an empty array if $sizes is empty.

In 3.4, $metadata['sizes'] would have been left unset.

#2 @SergeyBiryukov
8 years ago

  • Component changed from General to Media
  • Milestone changed from Awaiting Review to 3.5

#3 @nacin
8 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In 22571:

wp_generate_attachment_metadata() should not call WP_Image_Editor if there's nothing to resize. props mdawaffe. fixes #22438.

Note: See TracTickets for help on using tickets.