WordPress.org

Make WordPress Core

Opened 7 weeks ago

Closed 7 weeks ago

#48215 closed enhancement (duplicate)

PNG quality not handled with GD

Reported by: Iulia Cazan Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Media Keywords:
Focuses: Cc:
PR Number:

Description

The quality of the PNG images is not handled correctly with GD (in fact at all). To make this work it would be required two small changes:

  1. wp-includes/class-wp-image-editor-gd.php @ line 433 - pass the quality argument for the function used to make the image
    <?php
    if ( ! $this->make_image( $filename, 'imagepng', array( $image, $filename, $this->get_quality() ) ) ) {
            return new WP_Error( 'image_save_error', __( 'Image Editor Save Failed' ) );
    }
    
  1. wp-includes/class-wp-image-editor.php @ line 261 - append the quality verification in case the image is PNG (the quality range is 1 -> 9, not 1 -> 100 like for JPEG )
    <?php
    if ( 'image/png' == $this->mime_type ) {
            if ( $quality > 9 ) {
                    $quality = ceil( $quality / 10 );
                    $quality = ( 10 >= $quality ) ? 9 : $quality;
            }
    }
    


Change History (3)

#1 @Iulia Cazan
7 weeks ago

  • Component changed from General to Media

#2 @SergeyBiryukov
7 weeks ago

  • Keywords needs-patch added

#3 @birgire
7 weeks ago

  • Keywords needs-patch removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Thank you for the ticket and proposed patch @iulia-cazan

According to the PHP docs there's also the 0 for no compression and -1 for default zlib compression level (6). Also mentioned there the inverse scale mapping.

There's another older ticket #24380 about this topic, so please join the conversation there.

So I'm marking this one as a duplicate.

Note: See TracTickets for help on using tickets.