[wp-trac] [WordPress Trac] #40439: Save progress of intermediate image creation after upload

WordPress Trac noreply at wordpress.org
Tue Jun 11 22:18:28 UTC 2019


#40439: Save progress of intermediate image creation after upload
-------------------------------------------------+-------------------------
 Reporter:  mikeschroder                         |       Owner:
                                                 |  mikeschroder
     Type:  enhancement                          |      Status:  assigned
 Priority:  high                                 |   Milestone:  5.3
Component:  Media                                |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-testing needs-unit-  |     Focuses:  ui
  tests early                                    |
-------------------------------------------------+-------------------------

Comment (by azaozz):

 Been going back and forth on how to best make the changes to the
 `WP_Image_Editor_Imagick` and `WP_Image_Editor_GD` classes.

 The problem is that the `multi_resize()` function there wasn't designed
 for this. It "locks" the resizing and saving of image sub-sizes inside the
 loop and silences all errors. That prevents incremental saving of the
 image meta (the purpose of this ticket), and prevents showing "meaningful"
 errors in the UI.

 Furthermore the (public) `resize()` and `save()` functions cannot be used
 for the same image multiple times. The way it works is that after
 `resize()` is used, all will have to be reset and then a new instance
 created to be able to re-use the original image as source. (This is the
 reason the private `_save()` and `_resize()` are used in the loop in
 multi_resize().)

 Other "not great" thing there is that the attachment ID and image meta
 data are "unknown" while processing images. This removes the context and
 generally prevents any meaningful possibility of extending the
 functionality.

 The ways to fix that:

 1. Introduce another function similar to `multi_resize()` but without the
 loop. This is in the current patch. That function returns the new
 dimensions after each sub-size is created or returns the relevant error
 when it fails. The downside is that if a plugin extends `WP_Image_Editor`
 directly and replaces one of the default classes, it will be missing the
 new function. I did a quick search and seems there are few plugins that do
 this.

 2. Pass `attachment_ID` and `image_meta` as optional params when making
 new instance. This will let us add few actions inside the loop in
 `multi_resize()` and pass errors to the UI and incrementally update sub-
 size dimensions. This is not as straightforward as adding a specialized
 method but is still a workable solution. Again, it suffers from the same
 problem as 1, existing plugins will need to be updated to work properly.

 3. Another alternate possibility is to (try to) replace the functionality
 of `wp_get_image_editor()`, i.e. use `_wp_image_editor_choose()` and then
 extend the class that was chosen and overload the `multi-resize()` or
 `resize()` methods. This is somewhat risky as we will need to replace low-
 level functions like `_resize()` without knowing the exact PHP library
 used or its configuration.

 From these three options I'm thinking the first sounds best. The current
 patch has a fall-back in cases where one of the image editor classes is
 replaced by a plugin. It will take some time but plugins that do this will
 get updated and add the new `create_subsize()` method.

 What do you think? Any other ideas? :)

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/40439#comment:40>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list