Make WordPress Core

Opened 11 years ago

Last modified 5 years ago

#23424 new enhancement

WP_Image class for handling images from the media library

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


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 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 (7)

#1 @kirasong
10 years 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.

#2 @aaroncampbell
10 years 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()?

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

#4 @wonderboymusic
9 years ago

  • Milestone changed from Awaiting Review to Future Release

#5 @joemcgill
9 years 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?

This ticket was mentioned in Slack in #core-images by joemcgill. View the logs.

8 years ago

This ticket was mentioned in Slack in #core-images by joemcgill. View the logs.

8 years ago

Note: See TracTickets for help on using tickets.