From 93565e3f82ab36565270a0ed176283c8e395eb63 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Tue, 24 Aug 2010 08:48:46 +0000 Subject: [PATCH] Fixes for new ImageMagick: * (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 | 4 ++++ includes/media/Bitmap.php | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index bc5c4c7b4e..15cc91f497 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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. diff --git a/includes/media/Bitmap.php b/includes/media/Bitmap.php index 3bb585240a..3f39fab762 100644 --- a/includes/media/Bitmap.php +++ b/includes/media/Bitmap.php @@ -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}!" ) . -- 2.20.1