Make WordPress Core

Opened 5 years ago

Last modified 2 years ago

#24380 reopened enhancement

Missing Compression Parameter in WP_Image_Editor_GD — at Version 1

Reported by: MuViMoTV Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.5.1
Component: Media Keywords: has-patch dev-feedback needs-refresh
Focuses: Cc:

Description (last modified by SergeyBiryukov)

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...

Change History (2)

#1 @SergeyBiryukov
5 years ago

  • Component changed from Editor to Media
  • Description modified (diff)
Note: See TracTickets for help on using tickets.