WordPress.org

Make WordPress Core

Ticket #40415: 40415.2.diff

File 40415.2.diff, 2.9 KB (added by losangelos, 21 months ago)

Use a windowed resizing filter (Lanczos). Improve sharpening for better quality images. Use progressive compression for smaller size images.

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

    diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php
    index abb2150..e3f8e66 100644
    a b class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    285285         *
    286286         * @param int    $dst_w       The destination width.
    287287         * @param int    $dst_h       The destination height.
    288          * @param string $filter_name Optional. The Imagick filter to use when resizing. Default 'FILTER_TRIANGLE'.
     288         * @param string $filter_name Optional. The Imagick filter to use when resizing. Default 'FILTER_LANCZOS'.
    289289         * @param bool   $strip_meta  Optional. Strip all profiles, excluding color profiles, from the image. Default true.
    290290         * @return bool|WP_Error
    291291         */
    292         protected function thumbnail_image( $dst_w, $dst_h, $filter_name = 'FILTER_TRIANGLE', $strip_meta = true ) {
     292        protected function thumbnail_image( $dst_w, $dst_h, $filter_name = 'FILTER_LANCZOS', $strip_meta = true ) {
    293293                $allowed_filters = array(
    294294                        'FILTER_POINT',
    295295                        'FILTER_BOX',
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    309309                );
    310310
    311311                /**
     312                 * Filters to choose another resizing filter.
     313                 *
     314                 * @param string $filter_name Filter name. Default 'FILTER_LANCZOS';
     315                 */
     316                $filter_name = apply_filters( 'imagick_resize_filter', $filter_name );
     317
     318                /**
    312319                 * Set the filter value if '$filter_name' name is in our whitelist and the related
    313320                 * Imagick constant is defined or fall back to our default filter.
    314321                 */
    315322                if ( in_array( $filter_name, $allowed_filters ) && defined( 'Imagick::' . $filter_name ) ) {
    316323                        $filter = constant( 'Imagick::' . $filter_name );
    317324                } else {
    318                         $filter = defined( 'Imagick::FILTER_TRIANGLE' ) ? Imagick::FILTER_TRIANGLE : false;
     325                        $filter = defined( 'Imagick::FILTER_LANCZOS' ) ? Imagick::FILTER_LANCZOS : false;
    319326                }
    320327
    321328                /**
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    363370                        // Set appropriate quality settings after resizing.
    364371                        if ( 'image/jpeg' == $this->mime_type ) {
    365372                                if ( is_callable( array( $this->image, 'unsharpMaskImage' ) ) ) {
    366                                         $this->image->unsharpMaskImage( 0.25, 0.25, 8, 0.065 );
     373                                        $this->image->unsharpMaskImage( 1, 0.45, 3, 0 );
    367374                                }
    368375
    369376                                $this->image->setOption( 'jpeg:fancy-upsampling', 'off' );
    class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    399406                                }
    400407                        }
    401408
    402                         if ( is_callable( array( $this->image, 'setInterlaceScheme' ) ) && defined( 'Imagick::INTERLACE_NO' ) ) {
    403                                 $this->image->setInterlaceScheme( Imagick::INTERLACE_NO );
     409                        // Use progressive compression.
     410                        if ( is_callable( array( $this->image, 'setInterlaceScheme' ) ) && defined( 'Imagick::INTERLACE_PLANE' ) ) {
     411                                $this->image->setInterlaceScheme( Imagick::INTERLACE_PLANE );
    404412                        }
    405413                } catch ( Exception $e ) {
    406414                        return new WP_Error( 'image_resize_error', $e->getMessage() );