Index: includes/media/Bitmap.php =================================================================== --- includes/media/Bitmap.php (revision 95588) +++ includes/media/Bitmap.php (working copy) @@ -126,6 +126,7 @@ 'mimeType' => $image->getMimeType(), 'srcPath' => $image->getPath(), 'dstPath' => $dstPath, + 'ext' => strtolower(substr( $image->getPath(), strrpos( $image->getPath(), '.' ) + 1 )), 'dstUrl' => $dstUrl, ); @@ -141,7 +142,7 @@ } # Determine scaler type - $scaler = self::getScalerType( $dstPath ); + $scaler = self::getScalerType( $scalerParams['ext'], $dstPath ); wfDebug( __METHOD__ . ": scaler $scaler\n" ); if ( $scaler == 'client' ) { @@ -181,6 +182,9 @@ case 'custom': $err = $this->transformCustom( $image, $scalerParams ); break; + case 'customext': + $err = $this->transformCustomExt( $image, $scalerParams ); + break; case 'imext': $err = $this->transformImageMagickExt( $image, $scalerParams ); break; @@ -213,12 +217,14 @@ * * @return string client,im,custom,gd */ - protected static function getScalerType( $dstPath, $checkDstPath = true ) { - global $wgUseImageResize, $wgUseImageMagick, $wgCustomConvertCommand; + protected static function getScalerType( $ext, $dstPath, $checkDstPath = true ) { + global $wgUseImageResize, $wgUseImageMagick, $wgCustomConvertCommand, $wgCustomConvertCommandsByExtension; if ( !$dstPath && $checkDstPath ) { # No output path available, client side scaling only $scaler = 'client'; + } elseif (array_key_exists($ext, $wgCustomConvertCommandsByExtension)) { + $scaler = 'customext'; } elseif ( !$wgUseImageResize ) { $scaler = 'client'; } elseif ( $wgUseImageMagick ) { @@ -429,21 +435,19 @@ } /** - * Transform an image using a custom command + * Invoke an external image transformation command line on a given file, replacing + * %s by the source file path, %d by the destination file path, $w by the width, + * and %h by the height. * - * @param $image File File associated with this thumbnail + * @param $cmd string Command line, containing %s, %d, %w, and %h codes. * @param $params array Array with scaler params * * @return MediaTransformError Error object if error occured, false (=no error) otherwise */ - protected function transformCustom( $image, $params ) { - # Use a custom convert command - global $wgCustomConvertCommand; - - # Variables: %s %d %w %h + protected function transformCustomExecute( $cmd, $params ) { $src = wfEscapeShellArg( $params['srcPath'] ); $dst = wfEscapeShellArg( $params['dstPath'] ); - $cmd = $wgCustomConvertCommand; + $cmd = str_replace( '%s', $src, str_replace( '%d', $dst, $cmd ) ); # Filenames $cmd = str_replace( '%h', $params['physicalHeight'], str_replace( '%w', $params['physicalWidth'], $cmd ) ); # Size @@ -459,8 +463,35 @@ } return false; # No error } + + /** + * Transform an image using a custom command + * + * @param $image File File associated with this thumbnail + * @param $params array Array with scaler params + * + * @return MediaTransformError Error object if error occured, false (=no error) otherwise + */ + protected function transformCustom( $image, $params ) { + # Use a custom convert command + global $wgCustomConvertCommand; + return $this->transformCustomExecute($wgCustomConvertCommand, $params); + } /** + * Transform an image using an extension-specific custom command + * + * @param $image File File associated with this thumbnail + * @param $params array Array with scaler params + * + * @return MediaTransformError Error object if error occured, false (=no error) otherwise + */ + protected function transformCustomExt( $image, $params ) { + global $wgCustomConvertCommandsByExtension; + return $this->transformCustomExecute($wgCustomConvertCommandsByExtension[$params['ext']], $params); + } + + /** * Log an error that occured in an external process * * @param $retval int Index: includes/DefaultSettings.php =================================================================== --- includes/DefaultSettings.php (revision 95588) +++ includes/DefaultSettings.php (working copy) @@ -637,6 +637,20 @@ $wgCustomConvertCommand = false; /** + * Use another resizing converter but only for certain + * file extensions. Any extensions not included in this + * list will be handled by the generic mechanisms above. + * This list overrides all other settings for the + * included extensions. + * + * Example for pngscale: + * + * $wgCustomConvertCommandsByExtension['png'] = "pngscale %s %d %w %h"; + * + */ +$wgCustomConvertCommandsByExtension = array(); + +/** * Some tests and extensions use exiv2 to manipulate the EXIF metadata in some image formats. */ $wgExiv2Command = '/usr/bin/exiv2';