From 065f1ef45319fcd72f644911131d4c24f2182d5e Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Tue, 7 Jan 2025 21:06:24 +0000 Subject: [PATCH] Media: enable high bit depth resized image output with Imagick. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix an issue where uploaded HDR images were resized and output as SDR and thus significantly degraded from the original. When using Imagick, output images will now match the bit depth of the uploaded image. Add a new filter ‘image_max_bit_depth’ which developers can use to control the maximum bit depth for resized images. Props adamsilverstein, kirasong, gregbenz, apermo. Fixes #62285. Built from https://develop.svn.wordpress.org/trunk@59588 git-svn-id: http://core.svn.wordpress.org/trunk@58974 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-image-editor-imagick.php | 20 +++++++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/wp-includes/class-wp-image-editor-imagick.php b/wp-includes/class-wp-image-editor-imagick.php index dd8b9ad519..9abb631847 100644 --- a/wp-includes/class-wp-image-editor-imagick.php +++ b/wp-includes/class-wp-image-editor-imagick.php @@ -503,11 +503,23 @@ class WP_Image_Editor_Imagick extends WP_Image_Editor { } } - // Limit the bit depth of resized images to 8 bits per channel. + // Limit the bit depth of resized images. if ( is_callable( array( $this->image, 'getImageDepth' ) ) && is_callable( array( $this->image, 'setImageDepth' ) ) ) { - if ( 8 < $this->image->getImageDepth() ) { - $this->image->setImageDepth( 8 ); - } + /** + * Filters the maximum bit depth of resized images. + * + * This filter only applies when resizing using the Imagick editor since GD + * does not support getting or setting bit depth. + * + * Use this to adjust the maximum bit depth of resized images. + * + * @since 6.8.0 + * + * @param int $max_depth The maximum bit depth. Default is the input depth. + * @param int $image_depth The bit depth of the original image. + */ + $max_depth = apply_filters( 'image_max_bit_depth', $this->image->getImageDepth(), $this->image->getImageDepth() ); + $this->image->setImageDepth( $max_depth ); } } catch ( Exception $e ) { return new WP_Error( 'image_resize_error', $e->getMessage() ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 70c620caab..53071345ad 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.8-alpha-59587'; +$wp_version = '6.8-alpha-59588'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.