Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#48215 closed enhancement (duplicate)

PNG quality not handled with GD

Reported by: iulia-cazan's profile Iulia Cazan Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Media Keywords:
Focuses: Cc:

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
4 years ago

  • Component changed from General to Media

#2 @SergeyBiryukov
4 years ago

  • Keywords needs-patch added

#3 @birgire
4 years 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.