Fixes for new ImageMagick:
authorTim Starling <tstarling@users.mediawiki.org>
Tue, 24 Aug 2010 08:48:46 +0000 (08:48 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Tue, 24 Aug 2010 08:48:46 +0000 (08:48 +0000)
* (bug 24824) Support ImageMagick 6.5.6-2+ JPEG decoder size hint, to reduce memory usage when such an ImageMagick is used for scaling.
* Removed -size option since it doesn't act as a JPEG decoder size hint with recent ImageMagicks, and it may cause undesired behaviour in the future since it's documented to do something different now.
* Disable multithreaded behaviour in recent ImageMagick, to avoid a deadlock when a resource limit such as $wgMaxShellMemory is hit.
* Fixed some comments.

Replaces WMF live hack.

RELEASE-NOTES
includes/media/Bitmap.php

index bc5c4c7..15cc91f 100644 (file)
@@ -303,6 +303,10 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   a repository due to missing 'name' attribute from the API list=allimages
 * (bug 24898) MediaWiki uses /tmp even if a vHost-specific tempdir is set, also
   make wfTempDir() return a sane value for Windows on worst-case
+* (bug 24824) Support ImageMagick 6.5.6-2+ JPEG decoder size hint, to reduce 
+  memory usage when such an ImageMagick is used for scaling.
+* Disable multithreaded behaviour in recent ImageMagick, to avoid a deadlock 
+  when a resource limit such as $wgMaxShellMemory is hit.
 
 === API changes in 1.17 ===
 * (bug 22738) Allow filtering by action type on query=logevent.
index 3bb5852..3f39fab 100644 (file)
@@ -120,12 +120,15 @@ class BitmapHandler extends ImageHandler {
                        $scene = false;
                        $animation_pre = '';
                        $animation_post = '';
+                       $decoderHint = '';
                        if ( $mimeType == 'image/jpeg' ) {
                                $quality = "-quality 80"; // 80%
                                # Sharpening, see bug 6193
                                if ( ( $physicalWidth + $physicalHeight ) / ( $srcWidth + $srcHeight ) < $wgSharpenReductionThreshold ) {
                                        $sharpen = "-sharpen " . wfEscapeShellArg( $wgSharpenParameter );
                                }
+                               // JPEG decoder hint to reduce memory, available since IM 6.5.6-2
+                               $decoderHint = "-define jpeg:size={$physicalWidth}x{$physicalHeight}";
                        } elseif ( $mimeType == 'image/png' ) {
                                $quality = "-quality 95"; // zlib 9, adaptive filtering
                        } elseif( $mimeType == 'image/gif' ) {
@@ -150,20 +153,18 @@ class BitmapHandler extends ImageHandler {
                                $tempEnv = '';
                        }
 
-                       # Specify white background color, will be used for transparent images
-                       # in Internet Explorer/Windows instead of default black.
-
-                       # Note, we specify "-size {$physicalWidth}" and NOT "-size {$physicalWidth}x{$physicalHeight}".
-                       # It seems that ImageMagick has a bug wherein it produces thumbnails of
-                       # the wrong size in the second case.
-
                        $cmd  = 
                                $tempEnv .
+                               // Use one thread only, to avoid deadlock bugs on OOM
+                               'OMP_NUM_THREADS=1 ' .
                                wfEscapeShellArg( $wgImageMagickConvertCommand ) .
-                               " {$quality} -background white -size {$physicalWidth} ".
+                               // Specify white background color, will be used for transparent images
+                               // in Internet Explorer/Windows instead of default black.
+                               " {$quality} -background white".
+                               " {$decoderHint} " .
                                wfEscapeShellArg( $this->escapeMagickInput( $srcPath, $scene ) ) .
                                " {$animation_pre}" .
-                               // For the -resize option a "!" is needed to force exact size,
+                               // For the -thumbnail option a "!" is needed to force exact size,
                                // or ImageMagick may decide your ratio is wrong and slice off
                                // a pixel.
                                " -thumbnail " . wfEscapeShellArg( "{$physicalWidth}x{$physicalHeight}!" ) .