6 class SvgHandler
extends ImageHandler
{
8 global $wgSVGConverters, $wgSVGConverter;
9 if ( !isset( $wgSVGConverters[$wgSVGConverter] ) ) {
10 wfDebug( "\$wgSVGConverter is invalid, disabling SVG rendering.\n" );
17 function mustRender() {
21 function normaliseParams( $image, &$params ) {
23 if ( !parent
::normaliseParams( $image, $params ) ) {
27 # Don't make an image bigger than wgMaxSVGSize
28 $params['physicalWidth'] = $params['width'];
29 $params['physicalHeight'] = $params['height'];
30 if ( $params['physicalWidth'] > $wgSVGMaxSize ) {
31 $srcWidth = $image->getWidth( $params['page'] );
32 $srcHeight = $image->getHeight( $params['page'] );
33 $params['physicalWidth'] = $wgSVGMaxSize;
34 $params['physicalHeight'] = Image
::scaleHeight( $srcWidth, $srcHeight, $wgSVGMaxSize );
39 function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
40 global $wgSVGConverters, $wgSVGConverter, $wgSVGConverterPath;
42 if ( !$this->normaliseParams( $image, $params ) ) {
43 return new TransformParameterError( $params );
45 $clientWidth = $params['width'];
46 $clientHeight = $params['height'];
47 $physicalWidth = $params['physicalWidth'];
48 $physicalHeight = $params['physicalHeight'];
49 $srcWidth = $image->getWidth();
50 $srcHeight = $image->getHeight();
51 $srcPath = $image->getImagePath();
53 if ( $flags & self
::TRANSFORM_LATER
) {
54 return new ThumbnailImage( $dstUrl, $clientWidth, $clientHeight );
57 if ( !wfMkdirParents( dirname( $dstPath ) ) ) {
58 return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight,
59 wfMsg( 'thumbnail_dest_directory' ) );
63 if( isset( $wgSVGConverters[$wgSVGConverter] ) ) {
65 array( '$path/', '$width', '$height', '$input', '$output' ),
66 array( $wgSVGConverterPath ?
wfEscapeShellArg( "$wgSVGConverterPath/" ) : "",
67 intval( $physicalWidth ),
68 intval( $physicalHeight ),
69 wfEscapeShellArg( $srcPath ),
70 wfEscapeShellArg( $dstPath ) ),
71 $wgSVGConverters[$wgSVGConverter] ) . " 2>&1";
72 wfProfileIn( 'rsvg' );
73 wfDebug( __METHOD__
.": $cmd\n" );
74 $err = wfShellExec( $cmd, $retval );
75 wfProfileOut( 'rsvg' );
78 $removed = $this->removeBadFile( $dstPath, $retval );
79 if ( $retval != 0 ||
$removed ) {
80 wfDebugLog( 'thumbnail',
81 sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"',
82 wfHostname(), $retval, trim($err), $cmd ) );
83 return new MediaTransformError( 'thumbnail_error', $clientWidth, $clientHeight, $err );
85 return new ThumbnailImage( $dstUrl, $clientWidth, $clientHeight, $dstPath );
89 function getImageSize( $image, $path ) {
90 return wfGetSVGsize( $path );
93 function getThumbType( $ext, $mime ) {
94 return array( 'png', 'image/png' );