Add $wgJpegQuality to control jpg thumb quality
authorRyan Schmidt <skizzerz@skizzerz.net>
Thu, 19 Apr 2018 17:00:16 +0000 (10:00 -0700)
committerRyan Schmidt <skizzerz@skizzerz.net>
Thu, 19 Apr 2018 17:00:16 +0000 (10:00 -0700)
This new configuration variable defaults to 80, which is the current
quality in use when scaling jpeg thumbnails with ImageMagick. GD used a
quality of 95, which was reduced to 80 as a result of this change.

Bug: T192248
Change-Id: I94cad01cc876ef9083250f5d1989a73cd19617fb

RELEASE-NOTES-1.32
includes/DefaultSettings.php
includes/media/Bitmap.php

index 7971bcc..9eb751a 100644 (file)
@@ -9,6 +9,8 @@ production.
 * (T115414) The $wgEnableAPI and $wgEnableWriteAPI settings, deprecated in 1.31, have been removed.
 * The $wgUseAjax setting is now formally deprecated, and MediaWiki will act as if it is always set.
 * The $wgSiteSupportPage setting, unused since 1.5, was removed.
+* $wgJpegQuality was added to allow configuring the quality of JPEG thumbnails (default 80).
+* The default quality of JPEG thumbnails generated by GD was reduced from 95 to 80.
 * …
 
 === New features in 1.32 ===
index 1ea9a42..975e20a 100644 (file)
@@ -1085,6 +1085,15 @@ $wgJpegTran = '/usr/bin/jpegtran';
  */
 $wgJpegPixelFormat = 'yuv420';
 
+/**
+ * When scaling a JPEG thumbnail, this is the quality we request
+ * from the backend. It should be an int between 1 and 100,
+ * with 100 indicating 100% quality.
+ *
+ * @since 1.32
+ */
+$wgJpegQuality = 80;
+
 /**
  * Some tests and extensions use exiv2 to manipulate the Exif metadata in some
  * image formats.
index b88a34d..cda037c 100644 (file)
@@ -134,7 +134,8 @@ class BitmapHandler extends TransformationalImageHandler {
        protected function transformImageMagick( $image, $params ) {
                # use ImageMagick
                global $wgSharpenReductionThreshold, $wgSharpenParameter, $wgMaxAnimatedGifArea,
-                       $wgImageMagickTempDir, $wgImageMagickConvertCommand, $wgJpegPixelFormat;
+                       $wgImageMagickTempDir, $wgImageMagickConvertCommand, $wgJpegPixelFormat,
+                       $wgJpegQuality;
 
                $quality = [];
                $sharpen = [];
@@ -146,7 +147,7 @@ class BitmapHandler extends TransformationalImageHandler {
 
                if ( $params['mimeType'] == 'image/jpeg' ) {
                        $qualityVal = isset( $params['quality'] ) ? (string)$params['quality'] : null;
-                       $quality = [ '-quality', $qualityVal ?: '80' ]; // 80%
+                       $quality = [ '-quality', $qualityVal ?: (string)$wgJpegQuality ]; // 80% by default
                        if ( $params['interlace'] ) {
                                $animation_post = [ '-interlace', 'JPEG' ];
                        }
@@ -276,7 +277,7 @@ class BitmapHandler extends TransformationalImageHandler {
         */
        protected function transformImageMagickExt( $image, $params ) {
                global $wgSharpenReductionThreshold, $wgSharpenParameter, $wgMaxAnimatedGifArea,
-                       $wgJpegPixelFormat;
+                       $wgJpegPixelFormat, $wgJpegQuality;
 
                try {
                        $im = new Imagick();
@@ -293,7 +294,7 @@ class BitmapHandler extends TransformationalImageHandler {
                                        $im->sharpenImage( $radius, $sigma );
                                }
                                $qualityVal = isset( $params['quality'] ) ? (string)$params['quality'] : null;
-                               $im->setCompressionQuality( $qualityVal ?: 80 );
+                               $im->setCompressionQuality( $qualityVal ?: $wgJpegQuality );
                                if ( $params['interlace'] ) {
                                        $im->setInterlaceScheme( Imagick::INTERLACE_JPEG );
                                }
@@ -498,9 +499,19 @@ class BitmapHandler extends TransformationalImageHandler {
 
        /**
         * Callback for transformGd when transforming jpeg images.
+        *
+        * @param resource $dst_image Image resource of the original image
+        * @param string $thumbPath File path to write the thumbnail image to
+        * @param int|null $quality Quality of the thumbnail from 1-100,
+        *    or null to use default quality.
         */
-       // FIXME: transformImageMagick() & transformImageMagickExt() uses JPEG quality 80, here it's 95?
-       static function imageJpegWrapper( $dst_image, $thumbPath, $quality = 95 ) {
+       static function imageJpegWrapper( $dst_image, $thumbPath, $quality = null ) {
+               global $wgJpegQuality;
+
+               if ( $quality === null ) {
+                       $quality = $wgJpegQuality;
+               }
+
                imageinterlace( $dst_image );
                imagejpeg( $dst_image, $thumbPath, $quality );
        }