WordPress.org

Make WordPress Core

Opened 4 months ago

Last modified 4 months ago

#26737 new feature request

WP_Image_Editor should provide a query_formats function.

Reported by: dan.rossiter Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Media Keywords:
Focuses: Cc:

Description

In developing one of my plugins, I've had to circumvent the lack of a function in WP_Image_editor to list supported extensions. Although support is provided for checking whether a specific mime type is supported, this is not sufficient in some instances.

Implementation of such a feature in both of the inheriting classes (Imagick and GD) would be trivial since in Imagick the function could simply return Imagick::queryformats() and for GD a static array containing JPG, PNG, and GIF could be returned.

Change History (3)

comment:1 follow-up: markoheijnen4 months ago

Why isn't it enough to check if a specific mime type is supported? I'm not seeing the benefit for returning the formats with a method.

comment:2 in reply to: ↑ 1 dan.rossiter4 months ago

Replying to markoheijnen:

Why isn't it enough to check if a specific mime type is supported? I'm not seeing the benefit for returning the formats with a method.

Because that is a less flexible solution. Obviously anything that can be done by checking for support of an individual extension can be done for all WP-supported extensions, but sometimes it is cleaner to have access to the full list.

A specific example of such a case would be a bit of code I'm currently working on to support generation of thumbnails for arbitrary filetypes. Each of the many methods of generating a thumbnail is indexed by a regex matching all supported thumbnails. WP_Image_Editor is one of the ways that I can generate these thumbnails. With direct access to all supported extensions I can generate this index with much less overhead than if I were to iterate all WP-supported extensions and for each get the mime type, then check whether that mime type is supported.

comment:3 markoheijnen4 months ago

I still don't see the use case. I did a project that I had to generate thumbnails for TIFF images (not a web extension). Obviously then I check for TIFF in the beginning and change the mime type on save. If I get an error then the mime type isn't supported so I skip it. Also on plugin activation I check with wp_image_editor_supports( array( 'mime_type' => 'image/tiff' ) ) and if it's false I will disable the plugin again. This is something you maybe can do too. You only provide a list with the extensions you care about and let WordPress do it's own magic.

The current check method is flexible but not in the way to may prefer. If we add a query_formats method then it still don't have any value for you. You still need to loop all the existing image editors and combine the array. What leads to another issue and that is requesting all the image editors.

Note: See TracTickets for help on using tickets.