From 76ddb650b78645ed438190fd2e8a7b5ae8ac18a4 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Mon, 30 Sep 2024 23:48:49 +0000 Subject: [PATCH] Revert r59136 from the 6.5 branch, this is intended for trunk. git-svn-id: https://develop.svn.wordpress.org/branches/6.5@59144 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-image-editor-gd.php | 32 ------------------- .../class-wp-image-editor-imagick.php | 1 - tests/phpunit/tests/media.php | 28 ---------------- 3 files changed, 61 deletions(-) diff --git a/src/wp-includes/class-wp-image-editor-gd.php b/src/wp-includes/class-wp-image-editor-gd.php index cbc33007b9fb6..cbfa6dba382f4 100644 --- a/src/wp-includes/class-wp-image-editor-gd.php +++ b/src/wp-includes/class-wp-image-editor-gd.php @@ -567,38 +567,6 @@ protected function _save( $image, $filename = null, $mime_type = null ) { ); } - /** - * Sets Image Compression quality on a 1-100% scale. Handles WebP lossless images. - * - * @since 6.7.0 - * - * @param int $quality Compression Quality. Range: [1,100] - * @return true|WP_Error True if set successfully; WP_Error on failure. - */ - public function set_quality( $quality = null ) { - $quality_result = parent::set_quality( $quality ); - if ( is_wp_error( $quality_result ) ) { - return $quality_result; - } else { - $quality = $this->get_quality(); - } - - // Handle setting the quality for WebP lossless images, see https://php.watch/versions/8.1/gd-webp-lossless. - try { - if ( 'image/webp' === $this->mime_type && defined( 'IMG_WEBP_LOSSLESS' ) ) { - $webp_info = wp_get_webp_info( $this->file ); - if ( ! empty( $webp_info['type'] ) && 'lossless' === $webp_info['type'] ) { - $quality = IMG_WEBP_LOSSLESS; - parent::set_quality( $quality ); - } - } - } catch ( Exception $e ) { - return new WP_Error( 'image_quality_error', $e->getMessage() ); - } - $this->quality = $quality; - return true; - } - /** * Returns stream of current image. * diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php index bbac4c8fca738..5de01d7322fd5 100644 --- a/src/wp-includes/class-wp-image-editor-imagick.php +++ b/src/wp-includes/class-wp-image-editor-imagick.php @@ -215,7 +215,6 @@ public function set_quality( $quality = null ) { // Use WebP lossless settings. $this->image->setImageCompressionQuality( 100 ); $this->image->setOption( 'webp:lossless', 'true' ); - parent::set_quality( 100 ); } else { $this->image->setImageCompressionQuality( $quality ); } diff --git a/tests/phpunit/tests/media.php b/tests/phpunit/tests/media.php index 45ff9b40c9417..7cc9f5470f754 100644 --- a/tests/phpunit/tests/media.php +++ b/tests/phpunit/tests/media.php @@ -6081,34 +6081,6 @@ private function get_width_height_for_high_priority() { ); } - - /** - * Test WebP lossless quality is handled correctly. - * - * @ticket 60291 - */ - public function test_set_quality_webp_lossless() { - // Get a new editor to test that lossless WebP images are handled correctly. - $editor = wp_get_image_editor( DIR_TESTDATA . '/images/webp-lossless.webp' ); - - // If no editor is available, skip the test. - if ( is_wp_error( $editor ) ) { - $this->markTestSkipped( 'No editor available for lossless WebP images.' ); - } - - // Only test on GD when WebP lossless is supported. - if ( 'WP_Image_Editor_GD' === get_class( $editor ) && ! defined( 'IMG_WEBP_LOSSLESS' ) ) { - $this->markTestSkipped( 'No GD support available for lossless WebP images.' ); - } - - // Verify lossless quality is set correctly: IMG_WEBP_LOSSLESS for GD and 100 for Imagick. - if ( 'WP_Image_Editor_GD' === get_class( $editor ) ) { - $this->assertSame( IMG_WEBP_LOSSLESS, $editor->get_quality() ); - } else { - $this->assertSame( 100, $editor->get_quality() ); - } - } - /** * Returns an array with dimension attribute values ineligible for a high priority image. *