3 class SvgHandler
extends ImageHandler
{
5 global $wgSVGConverters, $wgSVGConverter;
6 if ( !isset( $wgSVGConverters[$wgSVGConverter] ) ) {
7 wfDebug( "\$wgSVGConverter is invalid, disabling SVG rendering.\n" );
14 function mustRender() {
18 function normaliseParams( $image, &$params ) {
20 if ( !parent
::normaliseParams( $image, $params ) ) {
24 # Don't make an image bigger than wgMaxSVGSize
25 $params['physicalWidth'] = $params['width'];
26 $params['physicalHeight'] = $params['height'];
27 if ( $params['physicalWidth'] > $wgSVGMaxSize ) {
28 $srcWidth = $image->getWidth( $params['page'] );
29 $srcHeight = $image->getHeight( $params['page'] );
30 $params['physicalWidth'] = $wgSVGMaxSize;
31 $params['physicalHeight'] = Image
::scaleHeight( $srcWidth, $srcHeight, $wgSVGMaxSize );
36 function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
37 global $wgSVGConverters, $wgSVGConverter, $wgSVGConverterPath;
39 if ( !$this->normaliseParams( $image, $params ) ) {
40 return new TransformParameterError( $params );
42 $clientWidth = $params['width'];
43 $clientHeight = $params['height'];
44 $physicalWidth = $params['physicalWidth'];
45 $physicalHeight = $params['physicalHeight'];
46 $srcWidth = $image->getWidth();
47 $srcHeight = $image->getHeight();
48 $srcPath = $image->getImagePath();
50 if ( $flags & self
::TRANSFORM_LATER
) {
51 return new ThumbnailImage( $dstUrl, $clientWidth, $clientHeight );
54 if ( !wfMkdirParents( dirname( $dstPath ) ) ) {
55 return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight,
56 wfMsg( 'thumbnail_dest_directory' ) );
60 if( isset( $wgSVGConverters[$wgSVGConverter] ) ) {
62 array( '$path/', '$width', '$height', '$input', '$output' ),
63 array( $wgSVGConverterPath ?
wfEscapeShellArg( "$wgSVGConverterPath/" ) : "",
64 intval( $physicalWidth ),
65 intval( $physicalHeight ),
66 wfEscapeShellArg( $srcPath ),
67 wfEscapeShellArg( $dstPath ) ),
68 $wgSVGConverters[$wgSVGConverter] ) . " 2>&1";
69 wfProfileIn( 'rsvg' );
70 wfDebug( __METHOD__
.": $cmd\n" );
71 $err = wfShellExec( $cmd, $retval );
72 wfProfileOut( 'rsvg' );
75 $removed = $this->removeBadFile( $dstPath, $retval );
76 if ( $retval != 0 ||
$removed ) {
77 wfDebugLog( 'thumbnail',
78 sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"',
79 wfHostname(), $retval, trim($err), $cmd ) );
80 return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight, $err );
82 return new ThumbnailImage( $dstUrl, $clientWidth, $clientHeight );
86 function getImageSize( $image, $path ) {
87 return wfGetSVGsize( $path );
90 function getThumbType( $ext, $mime ) {
91 return array( 'png', 'image/png' );