From 920fd72f13b04b34a54fca8b1a28e859edf809f5 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 10 Sep 2005 01:02:41 +0000 Subject: [PATCH] * Support SVG rendering with rsvg * Cap arbitrary SVG renders to given image size or $wgSVGMaxSize pixels wide --- RELEASE-NOTES | 2 ++ includes/DefaultSettings.php | 3 +++ includes/Image.php | 18 ++++++++++++------ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 1a0adacf21..2c2ac857d8 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index b47c44dbcc..347940b3e1 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 ) ) { diff --git a/includes/Image.php b/includes/Image.php index e162807878..39ceca5b59 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -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. -- 2.20.1