WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 8 weeks ago

#23424 new enhancement

WP_Image class for handling images from the media library

Reported by: markoheijnen Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.5
Component: Media Keywords: needs-patch dev-feedback
Focuses: Cc:

Description

Since 3.5 we have the class WP_Image_Editor. This needs a file path to be able to manipulate an image. Currently you would have to use something like wp_get_image_editor( _load_image_to_edit_path( $post_id ) ). What is wrong since you are using a "private" function.

Currently I'm working on this idea and you can find the code here https://github.com/markoheijnen/WP_Image/blob/master/wp-image.php. What it does now is getting the filepath, be able to get the image editor, add an image size on the fly and getting/updating the metadata.

We really miss something like a WP_Image class in WordPress. However I'm not sure what kind of functionality is needed for it. I like the current class mainly because it gives you the power to create an image size for a specific media image and stores it in the sizes array. When a user removes the media image then also the custom sizes will be removed.

Change History (5)

comment:1 @DH-Shredder15 months ago

I'd suggest submitting an initial patch here (even though it's basically just the file from GitHub), to see if we can get a little more feedback that way.

I'd love to see something like this hit core.

comment:2 @aaroncampbell13 months ago

Just dropping by here to say that I had to use the wp_get_image_editor( _load_image_to_edit_path( $attachment_id ) ) hack recently when trying to filter an image size to blur it.

I'm not sure if the whole WP_Image thing is really necessary for this particular case (of needing _load_image_to_edit_path()) though. It seems like WP_Image_Editor could simply add a load_image method that uses _load_image_to_edit_path() and the already existing load()?

comment:3 @markoheijnen13 months ago

WP_Image_Editor should not have any logic that relates with attachments. This to me should be done outside in a new function or WP_Image class.

comment:4 @wonderboymusic8 weeks ago

  • Milestone changed from Awaiting Review to Future Release

comment:5 @joemcgill8 weeks ago

I was thinking about the same issue recently and could see this being a nice enhancement over the current random group of functions used to CRUD image data. Would it be worth expanding this idea to include other media types as well, essentially creating a WP_Media class that could be a replacement for much of what is included in media.php?

Note: See TracTickets for help on using tickets.