diff --git src/wp-includes/media.php src/wp-includes/media.php
index 51c49f83d2..b4ee0b04dc 100644
|
|
function wp_get_image_editor( $path, $args = array() ) { |
3942 | 3942 | } |
3943 | 3943 | } |
3944 | 3944 | |
| 3945 | $mime_type = isset( $args['mime_type'] ) ? $args['mime_type'] : wp_check_filetype( $path )['type']; |
| 3946 | |
| 3947 | /** This filter is documented in wp-includes/class-wp-image-editor.php */ |
| 3948 | $output_format = apply_filters( 'image_editor_output_format', array(), $path, $mime_type ); |
| 3949 | if ( isset( $output_format[ $mime_type ] ) ) { |
| 3950 | $args['output_mime_type'] = $output_format[ $mime_type ]; |
| 3951 | } |
| 3952 | |
3945 | 3953 | $implementation = _wp_image_editor_choose( $args ); |
3946 | 3954 | |
3947 | 3955 | if ( $implementation ) { |
… |
… |
function _wp_image_editor_choose( $args = array() ) { |
3994 | 4002 | * 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD'. |
3995 | 4003 | */ |
3996 | 4004 | $implementations = apply_filters( 'wp_image_editors', array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) ); |
| 4005 | $supports_input = false; |
3997 | 4006 | |
3998 | 4007 | foreach ( $implementations as $implementation ) { |
3999 | 4008 | if ( ! call_user_func( array( $implementation, 'test' ), $args ) ) { |
4000 | 4009 | continue; |
4001 | 4010 | } |
4002 | 4011 | |
| 4012 | // Implementation should support the passed mime type. |
4003 | 4013 | if ( isset( $args['mime_type'] ) && |
4004 | 4014 | ! call_user_func( |
4005 | 4015 | array( $implementation, 'supports_mime_type' ), |
… |
… |
function _wp_image_editor_choose( $args = array() ) { |
4008 | 4018 | continue; |
4009 | 4019 | } |
4010 | 4020 | |
| 4021 | // Implementation should support requested methods. |
4011 | 4022 | if ( isset( $args['methods'] ) && |
4012 | 4023 | array_diff( $args['methods'], get_class_methods( $implementation ) ) ) { |
4013 | 4024 | |
4014 | 4025 | continue; |
4015 | 4026 | } |
4016 | 4027 | |
| 4028 | // Implementation should ideally support the output mime type as well if set and different than the passed type. |
| 4029 | if ( |
| 4030 | isset( $args['mime_type'] ) && |
| 4031 | isset( $args['output_mime_type'] ) && |
| 4032 | $args['mime_type'] !== $args['output_mime_type'] && |
| 4033 | ! call_user_func( array( $implementation, 'supports_mime_type' ), $args['output_mime_type'] ) |
| 4034 | ) { |
| 4035 | // This implementation supports the imput type but not the output type. |
| 4036 | // Keep looking to see if we can find an implementation that supports both. |
| 4037 | $supports_input = $implementation; |
| 4038 | continue; |
| 4039 | } |
| 4040 | |
| 4041 | // Favor the implementation that supports both input and output mime types. |
4017 | 4042 | return $implementation; |
4018 | 4043 | } |
4019 | 4044 | |
4020 | | return false; |
| 4045 | return $supports_input; |
4021 | 4046 | } |
4022 | 4047 | |
4023 | 4048 | /** |
diff --git tests/phpunit/tests/image/editor.php tests/phpunit/tests/image/editor.php
index c051ffec2b..9d0f674d2d 100644
|
|
class Tests_Image_Editor extends WP_Image_UnitTestCase { |
126 | 126 | $this->assertSame( 82, $editor->get_quality(), 'Default quality setting is 82.' ); |
127 | 127 | |
128 | 128 | // Quality should change to the output format's value. |
129 | | // A PNG image will be converted to WEBP whose quialty should be 86. |
| 129 | // A PNG image will be converted to WEBP whose quality should be 86. |
130 | 130 | $editor->save(); |
131 | 131 | $this->assertSame( 86, $editor->get_quality(), 'Output image format is WEBP. Quality setting for it should be 86.' ); |
132 | 132 | |