Make WordPress Core

Ticket #54476: 54476.3.diff

File 54476.3.diff, 2.3 KB (added by adamsilverstein, 3 years ago)
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index 51c49f83d2..4d38fa6b48 100644
    function wp_get_image_editor( $path, $args = array() ) { 
    39423942                }
    39433943        }
    39443944
     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
    39453953        $implementation = _wp_image_editor_choose( $args );
    39463954
    39473955        if ( $implementation ) {
    function _wp_image_editor_choose( $args = array() ) { 
    40004008                        continue;
    40014009                }
    40024010
     4011                // Implementation should support the passed mime type.
    40034012                if ( isset( $args['mime_type'] ) &&
    40044013                        ! call_user_func(
    40054014                                array( $implementation, 'supports_mime_type' ),
    function _wp_image_editor_choose( $args = array() ) { 
    40084017                        continue;
    40094018                }
    40104019
     4020                // Implementation should support the output mime type as well if set and different than the passed type.
     4021                if (
     4022                        isset( $args['mime_type'] ) &&
     4023                        isset( $args['output_mime_type'] ) &&
     4024                        $args['mime_type'] !== $args['output_mime_type'] &&
     4025                        ! call_user_func( array( $implementation, 'supports_mime_type' ), $args['output_mime_type'] )
     4026                ) {
     4027                        continue;
     4028                }
     4029
     4030                // Implementation should support requested methods.
    40114031                if ( isset( $args['methods'] ) &&
    40124032                        array_diff( $args['methods'], get_class_methods( $implementation ) ) ) {
    40134033
  • tests/phpunit/tests/image/editor.php

    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 { 
    126126                $this->assertSame( 82, $editor->get_quality(), 'Default quality setting is 82.' );
    127127
    128128                // 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.
    130130                $editor->save();
    131131                $this->assertSame( 86, $editor->get_quality(), 'Output image format is WEBP. Quality setting for it should be 86.' );
    132132