Make WordPress Core

Ticket #36477: 36477_1.diff

File 36477_1.diff, 1.0 KB (added by codex-m, 7 years ago)

Retain number of unique colors when resizing, save file size

  • src/wp-includes/class-wp-image-editor-imagick.php

     
    301301                        'FILTER_BESSEL',
    302302                        'FILTER_SINC',
    303303                );
    304 
     304               
    305305                /**
     306                 * If number of unique colors is already 256 or less,
     307                 * Use an filesize optimizing filter that will retain the same number of colors when resizing.
     308                 * This will reduce occurrences of having a resized image filesize very much larger than the original.
     309                 * @since 4.6.0
     310                 */     
     311               
     312                if ( is_callable( array( $this->image, 'getImageColors' ) ) ) {
     313                        $number_of_unique_colors = intval( $this->image->getImageColors() );
     314                        if ( $number_of_unique_colors <= 256 ) {
     315                                $filter_name = 'FILTER_POINT';
     316                        }
     317                }
     318               
     319                /**
    306320                 * Set the filter value if '$filter_name' name is in our whitelist and the related
    307321                 * Imagick constant is defined or fall back to our default filter.
    308322                 */