From 3fd3960175aed0487e77a3f742d2d6df8eeb5b60 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 18 Nov 2008 01:18:12 +0000 Subject: [PATCH] Refactor SvgHandler to have transformSvgToPng() function, which can be used for non-thumbnail purposes --- includes/media/SVG.php | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) diff --git a/includes/media/SVG.php b/includes/media/SVG.php index 2604e3b4e8..978749d3c4 100644 --- a/includes/media/SVG.php +++ b/includes/media/SVG.php @@ -27,7 +27,6 @@ class SvgHandler extends ImageHandler { if ( !parent::normaliseParams( $image, $params ) ) { return false; } - # Don't make an image bigger than wgMaxSVGSize $params['physicalWidth'] = $params['width']; $params['physicalHeight'] = $params['height']; @@ -60,32 +59,49 @@ class SvgHandler extends ImageHandler { return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight, wfMsg( 'thumbnail_dest_directory' ) ); } - + + $status = $this->transformSvgToPng( $srcPath, $dstPath, $physicalWidth, $physicalHeight ); + if( $status === true ) { + return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath ); + } else { + return $status; // MediaTransformError + } + } + + /* + * Transform an SVG file to PNG + * This function can be called outside of thumbnail contexts + * @param string $srcPath + * @param string $dstPath + * @param string $width + * @param string $height + * @returns TRUE/MediaTransformError + */ + public function transformSvgToPng( $srcPath, $dstPath, $width, $height ) { + global $wgSVGConverters, $wgSVGConverter, $wgSVGConverterPath; $err = false; - if( isset( $wgSVGConverters[$wgSVGConverter] ) ) { + if ( isset( $wgSVGConverters[$wgSVGConverter] ) ) { $cmd = str_replace( array( '$path/', '$width', '$height', '$input', '$output' ), array( $wgSVGConverterPath ? wfEscapeShellArg( "$wgSVGConverterPath/" ) : "", - intval( $physicalWidth ), - intval( $physicalHeight ), + intval( $width ), + intval( $height ), wfEscapeShellArg( $srcPath ), wfEscapeShellArg( $dstPath ) ), - $wgSVGConverters[$wgSVGConverter] ) . " 2>&1"; + $wgSVGConverters[$wgSVGConverter] + ) . " 2>&1"; wfProfileIn( 'rsvg' ); wfDebug( __METHOD__.": $cmd\n" ); $err = wfShellExec( $cmd, $retval ); wfProfileOut( 'rsvg' ); } - $removed = $this->removeBadFile( $dstPath, $retval ); if ( $retval != 0 || $removed ) { - wfDebugLog( 'thumbnail', - sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"', + wfDebugLog( 'thumbnail', sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"', wfHostname(), $retval, trim($err), $cmd ) ); return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight, $err ); - } else { - return new ThumbnailImage( $image, $dstUrl, $clientWidth, $clientHeight, $dstPath ); } + return true; } function getImageSize( $image, $path ) { -- 2.20.1