[wp-trac] [WordPress Trac] #55403: `wp_crop_image` returning incorrect file path when image formats filtered

WordPress Trac noreply at wordpress.org
Wed Mar 16 16:44:42 UTC 2022

#55403: `wp_crop_image` returning incorrect file path when image formats filtered
 Reporter:  Mat Lipe      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  5.8
 Severity:  normal        |   Keywords:
  Focuses:                |
 The `wp_crop_image` function calculates the destination file path based on
 the source file's extension.

 Version 5.8.0 introduced a new `image_editor_output_format` filter which
 allows you to change the output format (extension) of generated image
 sizes. If the generated image extension is changed, `wp_crop_images` does
 not honor the change and returns a broken path to an image with the
 correct name but the source files original (now incorrect) extension.

 Example filter which converts the extensions to webp:

 add_filter( 'image_editor_output_format', fn() => array_fill_keys( [
 'image/jpg', 'image/jpeg', 'image/png' ], 'image/webp' ) );

 Recreate steps:
 1. Add the example filter.
 2. Upload a JPEG or PNG to media library.
 3. Edit the uploaded image via the media library.
 4. Crop the image and save it.
 5. Notice the image is now broken and errors will display in browser

Ticket URL: <https://core.trac.wordpress.org/ticket/55403>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list