Make WordPress Core

Opened 2 months ago

Last modified 2 months ago

#54476 new defect (bug)

Improve image engine detection when output format adjusted with filter.

Reported by: adamsilverstein Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.8
Component: Media Keywords: has-patch
Focuses: Cc:


WordPress supports both Imagick and LibGD to generate sub sized images. When users upload a new image, the function wp_get_image_editor is called, which in turn passes the image to _wp_image_editor_choose which uses the file's mime type to determine which engine should be used for that image type.

In some cases, users have both Imagick and LibGD installed and each engine supports different formats. For example, LibGD supports WebP, but Imagick does not. WordPress picks the correct engine to use based on the images mime type. This works fine, except when we attempt to adjust the default output format using the new image_editor_output_format filter introduced in version 5.8.

I saw some reports on this on the modern image plugin, where the user could not output WebP images by default even though their system appears to support it. See https://github.com/adamsilverstein/modern-images-wp/issues/13. In these cases, WordPress picks the wrong engine for the image, and the sub size generation fails.

To fix this, we need to run the mime type through the same transformation we do in get_output_format before calling _wp_image_editor_choose.

Patch incoming.

Attachments (1)

54476.diff (628 bytes) - added by adamsilverstein 2 months ago.

Download all attachments as: .zip

Change History (3)

This ticket was mentioned in PR #1918 on WordPress/wordpress-develop by adamsilverstein.

2 months ago

  • Keywords has-patch added

#2 @mikeschroder
2 months ago

Thanks so much for the patch! Will be glad to see this addressed.

I left a question / comment over on the GitHub side.

Note: See TracTickets for help on using tickets.