Make WordPress Core

Ticket #54356: 54356.2.diff

File 54356.2.diff, 3.2 KB (added by adamsilverstein, 2 years ago)
  • src/wp-includes/class-wp-image-editor.php

    diff --git src/wp-includes/class-wp-image-editor.php src/wp-includes/class-wp-image-editor.php
    index ccf43402a6..cc05c0247c 100644
    abstract class WP_Image_Editor { 
    240240                // Use the output mime type if present. If not, fall back to the input/initial mime type.
    241241                $mime_type = ! empty( $this->output_mime_type ) ? $this->output_mime_type : $this->mime_type;
    242242                // Get the default quality setting for the mime type.
    243                 $default_quality = $this->get_default_quality( $mime_type );
     243                $default_quality = $this->get_default_quality();
    244244
    245245                if ( null === $quality ) {
    246246                        /**
    abstract class WP_Image_Editor { 
    297297        }
    298298
    299299        /**
    300          * Returns the default compression quality setting for the mime type.
     300         * Returns the default compression quality setting.
    301301         *
    302302         * @since 5.8.1
     303         * @since 6.1.0 Deprecated the `$mime_type` parameter. All mime types use the same default quality.
    303304         *
    304          * @param string $mime_type
    305          * @return int The default quality setting for the mime type.
     305         * @param string $mime_type Deprecated.
     306         * @return int The default quality setting.
    306307         */
    307308        protected function get_default_quality( $mime_type ) {
    308                 switch ( $mime_type ) {
    309                         case 'image/webp':
    310                                 $quality = 86;
    311                                 break;
    312                         case 'image/jpeg':
    313                         default:
    314                                 $quality = $this->default_quality;
    315                 }
    316 
    317                 return $quality;
     309                return $this->default_quality;
    318310        }
    319311
    320312        /**
  • tests/phpunit/tests/image/editor.php

    diff --git tests/phpunit/tests/image/editor.php tests/phpunit/tests/image/editor.php
    index c051ffec2b..524d64f228 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 82.
    130130                $editor->save();
    131                 $this->assertSame( 86, $editor->get_quality(), 'Output image format is WEBP. Quality setting for it should be 86.' );
     131                $this->assertSame( 82, $editor->get_quality(), 'Output image format is WEBP. Quality setting for it should be 82.' );
    132132
    133133                // Removing PNG to WEBP conversion on save. Quality setting should reset to the default.
    134134                $editor->reset_output_mime_type();
    class Tests_Image_Editor extends WP_Image_UnitTestCase { 
    150150                $this->assertSame( 56, $editor->get_quality(), 'Filtered default quality for JPEG is 56.' );
    151151
    152152                // Quality should change to the output format's value as filtered above.
    153                 // A JPEG image will be converted to WEBP whose quialty should be 42.
     153                // A JPEG image will be converted to WEBP whose quality should be 42.
    154154                $editor->save();
    155                 $this->assertSame( 42, $editor->get_quality(), 'Image conversion from JPEG to WEBP. Filtered WEBP quality shoild be 42.' );
     155                $this->assertSame( 42, $editor->get_quality(), 'Image conversion from JPEG to WEBP. Filtered WEBP quality should be 42.' );
    156156
    157157                // After removing the conversion the quality setting should reset to the filtered value for the original image type, JPEG.
    158158                $editor->reset_output_mime_type();