Make WordPress Core


Ignore:
Timestamp:
08/26/2025 08:55:24 PM (5 months ago)
Author:
adamsilverstein
Message:

Media: improve Imagick handling of indexed PNG images with transparency.

Fix an issue where certain transparent PNG images experienced noticeable quality degradation when resized by Imagick.

Follow up to [60246].

Props elvismdev, SirLouen, siliconforks, nosilver4u, iamshashank.

Fixes #63448.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/image/editorImagick.php

    r60246 r60667  
    874874        );
    875875    }
     876
     877    /**
     878     * Tests that alpha transparency is preserved after resizing.
     879     *
     880     * @ticket 63448
     881     * @dataProvider data_alpha_transparency_is_preserved_after_resize
     882     *
     883     * @param string $file_path Path to the image file.
     884     */
     885    public function test_alpha_transparency_is_preserved_after_resize( $file_path ) {
     886
     887        $temp_file = DIR_TESTDATA . '/images/test-temp.png';
     888
     889        $imagick_image_editor = new WP_Image_Editor_Imagick( $file_path );
     890        $imagick_image_editor->load();
     891
     892        $size = $imagick_image_editor->get_size();
     893        $imagick_image_editor->resize( $size['width'] * 0.5, $size['height'] * 0.5 );
     894        $imagick_image_editor->save( $temp_file );
     895
     896        $imagick             = new Imagick( $temp_file );
     897        $alpha_channel_depth = $imagick->getImageChannelDepth( Imagick::CHANNEL_ALPHA );
     898
     899        unlink( $temp_file );
     900
     901        $this->assertGreaterThan( 1, $alpha_channel_depth, "Alpha transparency should be preserved after resize for {$file_path}." );
     902    }
     903
     904    public static function data_alpha_transparency_is_preserved_after_resize() {
     905        return array(
     906            'oval-or8'                   => array(
     907                DIR_TESTDATA . '/images/png-tests/oval-or8.png',
     908            ),
     909            'oval-or8-grayscale-indexed' => array(
     910                DIR_TESTDATA . '/images/png-tests/oval-or8-grayscale-indexed.png',
     911            ),
     912        );
     913    }
    876914}
Note: See TracChangeset for help on using the changeset viewer.