Add support for some alternate SVG rasterizers:
authorBrion Vibber <brion@users.mediawiki.org>
Wed, 6 Oct 2004 10:33:22 +0000 (10:33 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Wed, 6 Oct 2004 10:33:22 +0000 (10:33 +0000)
* 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
includes/Image.php

index f22f41b..6f0fc3c 100644 (file)
@@ -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.
index 6d73c86..438b2e9 100644 (file)
@@ -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.