Make WordPress Core


Ignore:
Timestamp:
09/30/2024 06:37:05 PM (2 years 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
  • branches/6.5/tests/phpunit/tests/media.php

    r57687 r59136  
    60826082        }
    60836083
     6084
     6085        /**
     6086         * Test WebP lossless quality is handled correctly.
     6087         *
     6088         * @ticket 60291
     6089         */
     6090        public function test_set_quality_webp_lossless() {
     6091                // Get a new editor to test that lossless WebP images are handled correctly.
     6092                $editor = wp_get_image_editor( DIR_TESTDATA . '/images/webp-lossless.webp' );
     6093
     6094                // If no editor is available, skip the test.
     6095                if ( is_wp_error( $editor ) ) {
     6096                        $this->markTestSkipped( 'No editor available for lossless WebP images.' );
     6097                }
     6098
     6099                // Only test on GD when WebP lossless is supported.
     6100                if ( 'WP_Image_Editor_GD' === get_class( $editor ) && ! defined( 'IMG_WEBP_LOSSLESS' ) ) {
     6101                        $this->markTestSkipped( 'No GD support available for lossless WebP images.' );
     6102                }
     6103
     6104                // Verify lossless quality is set correctly: IMG_WEBP_LOSSLESS for GD and 100 for Imagick.
     6105                if ( 'WP_Image_Editor_GD' === get_class( $editor ) ) {
     6106                        $this->assertSame( IMG_WEBP_LOSSLESS, $editor->get_quality() );
     6107                } else {
     6108                        $this->assertSame( 100, $editor->get_quality() );
     6109                }
     6110        }
     6111
    60846112        /**
    60856113         * Returns an array with dimension attribute values ineligible for a high priority image.
Note: See TracChangeset for help on using the changeset viewer.