* Support SVG rendering with rsvg
authorBrion Vibber <brion@users.mediawiki.org>
Sat, 10 Sep 2005 01:02:41 +0000 (01:02 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Sat, 10 Sep 2005 01:02:41 +0000 (01:02 +0000)
* Cap arbitrary SVG renders to given image size or $wgSVGMaxSize pixels wide

RELEASE-NOTES
includes/DefaultSettings.php
includes/Image.php

index 1a0adac..2c2ac85 100644 (file)
@@ -88,6 +88,8 @@ fully support the editing toolbar, but was found to be too confusing.
   text loads or other fields mucking up XML export output
 * Add UploadVerification hook for custom file upload validation/security checks
 * (bug 3063) Remove some hardcodings from Hebrew localisation
+* Support SVG rendering with rsvg
+* Cap arbitrary SVG renders to given image size or $wgSVGMaxSize pixels wide
 
 
 === Caveats ===
index b47c44d..347940b 100644 (file)
@@ -1117,11 +1117,14 @@ $wgSVGConverters = array(
        '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',
+       'rsvg' => '$path/rsvg -w$width -h$height $input $output',
        );
 /** Pick one of the above */
 $wgSVGConverter = 'ImageMagick';
 /** If not in the executable PATH, specify */
 $wgSVGConverterPath = '';
+/** Don't scale a SVG larger than this unless its native size is larger */
+$wgSVGMaxSize = 1024;
 
 /** Set $wgCommandLineMode if it's not set already, to avoid notices */
 if( !isset( $wgCommandLineMode ) ) {
index e162807..39ceca5 100644 (file)
@@ -580,7 +580,7 @@ class Image
                
                if (!$mime || $mime==='unknown' || $mime==='unknown/unknown') return false;
                
-               #if it's SVG, check if ther's a converter enabled    
+               #if it's SVG, check if there's a converter enabled    
                if ($mime === 'image/svg') {
                        global $wgSVGConverters, $wgSVGConverter;
                        
@@ -934,7 +934,11 @@ class Image
                        return null;
                }
 
-               if( $width >= $this->width && !$this->mustRender() ) {
+               global $wgSVGMaxSize;
+               $maxsize = $this->mustRender()
+                       ? max( $this->width, $wgSVGMaxSize )
+                       : $this->width - 1;
+               if( $width > $maxsize ) {
                        # Don't make an image bigger than the source
                        $thumb = new ThumbnailImage( $this->getViewURL(), $this->getWidth(), $this->getHeight() );
                        wfProfileOut( $fname );
@@ -1007,12 +1011,14 @@ class Image
                        if( isset( $wgSVGConverters[$wgSVGConverter] ) ) {
                                global $wgSVGConverterPath;
                                $cmd = str_replace(
-                                       array( '$path/', '$width', '$input', '$output' ),
-                                       array( $wgSVGConverterPath,
-                                                  $width,
+                                       array( '$path/', '$width', '$height', '$input', '$output' ),
+                                       array( $wgSVGConverterPath ? "$wgSVGConverterPath/" : "",
+                                                  intval( $width ),
+                                                  intval( $height ),
                                                   wfEscapeShellArg( $this->imagePath ),
                                                   wfEscapeShellArg( $thumbPath ) ),
                                        $wgSVGConverters[$wgSVGConverter] );
+                               wfDebug( "reallyRenderThumb SVG: $cmd\n" );
                                $conv = shell_exec( $cmd );
                        } else {
                                $conv = false;
@@ -1025,7 +1031,7 @@ class Image
                                " -quality 85 -background white -size {$width}x{$height} ".
                                wfEscapeShellArg($this->imagePath) . " -resize {$width}x{$height} " .
                                wfEscapeShellArg($thumbPath);                           
-                       wfDebug("reallyRenderThumb: running ImageMagick: $cmd");
+                       wfDebug("reallyRenderThumb: running ImageMagick: $cmd\n");
                        $conv = shell_exec( $cmd );
                } else {
                        # Use PHP's builtin GD library functions.