[wp-trac] [WordPress Trac] #24380: Missing Compression Parameter in WP_Image_Editor_GD

WordPress Trac noreply at wordpress.org
Tue May 21 02:37:07 UTC 2013


#24380: Missing Compression Parameter in WP_Image_Editor_GD
--------------------------+-----------------------------
 Reporter:  MuViMoTV      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Editor        |    Version:  3.5.1
 Severity:  normal        |   Keywords:  needs-patch
--------------------------+-----------------------------
 Setting the image quality parameter has no effect on png files.

 Going through the wp-includes/class-wp-image-editor-gd.php

 I noticed that the compression parameter for the imagepng function call is
 missing.

 the current quality parameter only affects jpeg files.

 for jpeg, quality goes from 0->100 from bad to good

 for png, from 0->9 from good to bad.

 in the elseif  block starting at line 337 i have added a variable called
 compression and changed the code as follow:

 elseif ( 'image/png' == $mime_type ) {
                         // convert from full colors to index colors, like
 original PNG.
                         if ( function_exists('imageistruecolor') && !
 imageistruecolor( $image ) )
                                 imagetruecolortopalette( $image, false,
 imagecolorstotal( $image ) );

                         $compression = -((9/100*$this->quality)-9);

                         if ( ! $this->make_image( $filename, 'imagepng',
 array( $image, $filename, $compression ) ) )
                                 return new WP_Error( 'image_save_error',
 __('Image Editor Save Failed') );
                 }

 This convert the scale 0->100 into a 0->9 scale that matches the
 parameters from imaging.

 This gives back control to the user on image quality for png files...

--
Ticket URL: <http://core.trac.wordpress.org/ticket/24380>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list