Make WordPress Core


Ignore:
Timestamp:
01/07/2025 09:04:35 PM (3 months ago)
Author:
adamsilverstein
Message:

Media: enable high bit depth resized image output with Imagick.

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-image-editor-imagick.php

    r59473 r59588  
    504504            }
    505505
    506             // Limit the bit depth of resized images to 8 bits per channel.
     506            // Limit the bit depth of resized images.
    507507            if ( is_callable( array( $this->image, 'getImageDepth' ) ) && is_callable( array( $this->image, 'setImageDepth' ) ) ) {
    508                 if ( 8 < $this->image->getImageDepth() ) {
    509                     $this->image->setImageDepth( 8 );
    510                 }
     508                /**
     509                 * Filters the maximum bit depth of resized images.
     510                 *
     511                 * This filter only applies when resizing using the Imagick editor since GD
     512                 * does not support getting or setting bit depth.
     513                 *
     514                 * Use this to adjust the maximum bit depth of resized images.
     515                 *
     516                 * @since 6.8.0
     517                 *
     518                 * @param int $max_depth   The maximum bit depth. Default is the input depth.
     519                 * @param int $image_depth The bit depth of the original image.
     520                 */
     521                $max_depth = apply_filters( 'image_max_bit_depth', $this->image->getImageDepth(), $this->image->getImageDepth() );
     522                $this->image->setImageDepth( $max_depth );
    511523            }
    512524        } catch ( Exception $e ) {
Note: See TracChangeset for help on using the changeset viewer.