From 061ab795461ff47c1eadba96cc7fd9ddee3e3159 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 6 Oct 2004 10:33:22 +0000 Subject: [PATCH] Add support for some alternate SVG rasterizers: * ImageMagick - scaling is done after rasterization, and curves don't look good * Batik - looks good; requires Java * Sodipodi & Inkscape - haven't got them actually working yet; they crash on my mac when called from the web server though they work on the command line --- includes/DefaultSettings.php | 14 ++++++++++++++ includes/Image.php | 19 +++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index f22f41b431..6f0fc3c075 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -551,6 +551,20 @@ $wgUseImageResize = false; $wgUseImageMagick = false; $wgImageMagickConvertCommand = '/usr/bin/convert'; +# Scalable Vector Graphics (SVG) may be uploaded as images. +# Since SVG support is not yet standard in browsers, it is +# necessary to rasterize SVGs to PNG as a fallback format. +# +# An external program is required to perform this conversion: +$wgSVGConverters = array( + 'ImageMagick' => '$path/convert -background white -geometry $width $input $output', + 'sodipodi' => '$path/sodipodi -z -w $width -f $input -e $output', + 'inkscape' => '$path/inkscape -z -w $width -f $input -e $output', + 'batik' => 'java -Djava.awt.headless=true -jar $path/batik-rasterizer.jar -w $width -d $output $input', + ); +$wgSVGConverter = 'ImageMagick'; # Pick one of the above +$wgSVGConverterPath = ''; # If not in the executable PATH, specify + # PHPTal is a library for page templates. MediaWiki includes # a recent PHPTal distribution. It is required to use the # Monobook (default) skin. diff --git a/includes/Image.php b/includes/Image.php index 6d73c86a20..438b2e9702 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -325,13 +325,28 @@ class Image return ''; } - if( $width > $this->width ) { + if( $width > $this->width && !$this->mustRender() ) { # Don't make an image bigger than the source return $this->getViewURL(); } if ( (! file_exists( $thumbPath ) ) || ( filemtime($thumbPath) < filemtime($this->imagePath) ) ) { - if ( $wgUseImageMagick ) { + if( $this->extension == 'svg' ) { + global $wgSVGConverters, $wgSVGConverter; + if( isset( $wgSVGConverters[$wgSVGConverter] ) ) { + global $wgSVGConverterPath; + $cmd = str_replace( + array( '$path/', '$width', '$input', '$output' ), + array( $wgSVGConverterPath, + $width, + escapeshellarg( $this->imagePath ), + escapeshellarg( $thumbPath ) ), + $wgSVGConverters[$wgSVGConverter] ); + $conv = shell_exec( $cmd ); + } else { + $conv = false; + } + } elseif ( $wgUseImageMagick ) { # use ImageMagick # Specify white background color, will be used for transparent images # in Internet Explorer/Windows instead of default black. -- 2.20.1