Make WordPress Core


Ignore:
Timestamp:
09/30/2024 11:54:49 PM (4 months ago)
Author:
adamsilverstein
Message:

Media: improve support for lossless WebP.

When uploading lossless WebP images, WordPress now correctly outputs lossless WebP with both the Imagick and GD image editors.

Props: adamsilverstein, martinkrcho.
Fixes #60291.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/media.php

    r59118 r59145  
    61046104    }
    61056105
     6106
     6107    /**
     6108     * Test WebP lossless quality is handled correctly.
     6109     *
     6110     * @ticket 60291
     6111     */
     6112    public function test_set_quality_webp_lossless() {
     6113        // Get a new editor to test that lossless WebP images are handled correctly.
     6114        $editor = wp_get_image_editor( DIR_TESTDATA . '/images/webp-lossless.webp' );
     6115
     6116        // If no editor is available, skip the test.
     6117        if ( is_wp_error( $editor ) ) {
     6118            $this->markTestSkipped( 'No editor available for lossless WebP images.' );
     6119        }
     6120
     6121        // Only test on GD when WebP lossless is supported.
     6122        if ( 'WP_Image_Editor_GD' === get_class( $editor ) && ! defined( 'IMG_WEBP_LOSSLESS' ) ) {
     6123            $this->markTestSkipped( 'No GD support available for lossless WebP images.' );
     6124        }
     6125
     6126        // Verify lossless quality is set correctly: IMG_WEBP_LOSSLESS for GD and 100 for Imagick.
     6127        if ( 'WP_Image_Editor_GD' === get_class( $editor ) ) {
     6128            $this->assertSame( IMG_WEBP_LOSSLESS, $editor->get_quality() );
     6129        } else {
     6130            $this->assertSame( 100, $editor->get_quality() );
     6131        }
     6132    }
     6133
    61066134    /**
    61076135     * Test generated markup for an image with lazy loading gets auto-sizes.
Note: See TracChangeset for help on using the changeset viewer.