From 552d84a8a82091cbf4ad3c0bf250dc8cbda08237 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Fri, 30 May 2014 20:06:14 +0000 Subject: [PATCH] In `WP_Image_Editor_GD::_save()`, pass `$compression_level` into the args array for `->make_image()`. Props MuViMoTV, markoheijnen, SergeyBiryukov, mikemanger, ericlewis. Fixes #24380. Built from https://develop.svn.wordpress.org/trunk@28640 git-svn-id: http://core.svn.wordpress.org/trunk@28458 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-image-editor-gd.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/wp-includes/class-wp-image-editor-gd.php b/wp-includes/class-wp-image-editor-gd.php index be6e6f475f..79111bfc53 100644 --- a/wp-includes/class-wp-image-editor-gd.php +++ b/wp-includes/class-wp-image-editor-gd.php @@ -383,8 +383,15 @@ class WP_Image_Editor_GD extends WP_Image_Editor { if ( function_exists('imageistruecolor') && ! imageistruecolor( $image ) ) imagetruecolortopalette( $image, false, imagecolorstotal( $image ) ); - if ( ! $this->make_image( $filename, 'imagepng', array( $image, $filename ) ) ) + /* + * Invert the 1-100 quality scale and constrain it to 0-9, + * as per imagepng()'s peculiar quality parameter. + */ + $compression_level = floor( ( 101 - $this->quality ) * 0.09 ); + + if ( ! $this->make_image( $filename, 'imagepng', array( $image, $filename, $compression_level ) ) ) { return new WP_Error( 'image_save_error', __('Image Editor Save Failed') ); + } } elseif ( 'image/jpeg' == $mime_type ) { if ( ! $this->make_image( $filename, 'imagejpeg', array( $image, $filename, $this->quality ) ) )