Index: trunk/phase3/CREDITS |
— | — | @@ -65,6 +65,7 @@ |
66 | 66 | * Tom Gries |
67 | 67 | * Trevor Parscal |
68 | 68 | * Victor Vasiliev |
| 69 | +* Yesid Carrillo |
69 | 70 | * Yuri Astrakhan |
70 | 71 | |
71 | 72 | == Patch Contributors == |
Index: trunk/phase3/includes/media/SVG.php |
— | — | @@ -119,19 +119,32 @@ |
120 | 120 | $err = false; |
121 | 121 | $retval = ''; |
122 | 122 | if ( isset( $wgSVGConverters[$wgSVGConverter] ) ) { |
123 | | - $cmd = str_replace( |
124 | | - array( '$path/', '$width', '$height', '$input', '$output' ), |
125 | | - array( $wgSVGConverterPath ? wfEscapeShellArg( "$wgSVGConverterPath/" ) : "", |
126 | | - intval( $width ), |
127 | | - intval( $height ), |
128 | | - wfEscapeShellArg( $srcPath ), |
129 | | - wfEscapeShellArg( $dstPath ) ), |
130 | | - $wgSVGConverters[$wgSVGConverter] |
131 | | - ) . " 2>&1"; |
132 | | - wfProfileIn( 'rsvg' ); |
133 | | - wfDebug( __METHOD__.": $cmd\n" ); |
134 | | - $err = wfShellExec( $cmd, $retval ); |
135 | | - wfProfileOut( 'rsvg' ); |
| 123 | + if ( is_array( $wgSVGConverters[$wgSVGConverter] ) ) { |
| 124 | + // This is a PHP callable |
| 125 | + $func = $wgSVGConverters[$wgSVGConverter][0]; |
| 126 | + $args = array_merge( array( $srcPath, $dstPath, $width, $height ), |
| 127 | + array_slice( $wgSVGConverters[$wgSVGConverter], 1 ) ); |
| 128 | + if ( !is_callable( $func ) ) { |
| 129 | + throw new MWException( "$func is not callable" ); |
| 130 | + } |
| 131 | + $err = call_user_func_array( $func, $args ); |
| 132 | + $retval = (bool)$err; |
| 133 | + } else { |
| 134 | + // External command |
| 135 | + $cmd = str_replace( |
| 136 | + array( '$path/', '$width', '$height', '$input', '$output' ), |
| 137 | + array( $wgSVGConverterPath ? wfEscapeShellArg( "$wgSVGConverterPath/" ) : "", |
| 138 | + intval( $width ), |
| 139 | + intval( $height ), |
| 140 | + wfEscapeShellArg( $srcPath ), |
| 141 | + wfEscapeShellArg( $dstPath ) ), |
| 142 | + $wgSVGConverters[$wgSVGConverter] |
| 143 | + ) . " 2>&1"; |
| 144 | + wfProfileIn( 'rsvg' ); |
| 145 | + wfDebug( __METHOD__.": $cmd\n" ); |
| 146 | + $err = wfShellExec( $cmd, $retval ); |
| 147 | + wfProfileOut( 'rsvg' ); |
| 148 | + } |
136 | 149 | } |
137 | 150 | $removed = $this->removeBadFile( $dstPath, $retval ); |
138 | 151 | if ( $retval != 0 || $removed ) { |
— | — | @@ -141,6 +154,20 @@ |
142 | 155 | } |
143 | 156 | return true; |
144 | 157 | } |
| 158 | + |
| 159 | + public static function rasterizeImagickExt( $srcPath, $dstPath, $width, $height ) { |
| 160 | + $im = new Imagick( $srcPath ); |
| 161 | + $im->setImageFormat( 'png' ); |
| 162 | + $im->setBackgroundColor( 'transparent' ); |
| 163 | + $im->setImageDepth( 8 ); |
| 164 | + |
| 165 | + if ( !$im->thumbnailImage( intval( $width ), intval( $height ), /* fit */ false ) ) { |
| 166 | + return 'Could not resize image'; |
| 167 | + } |
| 168 | + if ( !$im->writeImage( $dstPath ) ) { |
| 169 | + return "Could not write to $dstPath"; |
| 170 | + } |
| 171 | + } |
145 | 172 | |
146 | 173 | /** |
147 | 174 | * @param $file File |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -660,6 +660,8 @@ |
661 | 661 | * necessary to rasterize SVGs to PNG as a fallback format. |
662 | 662 | * |
663 | 663 | * An external program is required to perform this conversion. |
| 664 | + * If set to an array, the first item is a PHP callable and any further items |
| 665 | + * are passed as parameters after $srcPath, $dstPath, $width, $height |
664 | 666 | */ |
665 | 667 | $wgSVGConverters = array( |
666 | 668 | 'ImageMagick' => '$path/convert -background white -thumbnail $widthx$height\! $input PNG:$output', |
— | — | @@ -668,6 +670,7 @@ |
669 | 671 | 'batik' => 'java -Djava.awt.headless=true -jar $path/batik-rasterizer.jar -w $width -d $output $input', |
670 | 672 | 'rsvg' => '$path/rsvg -w$width -h$height $input $output', |
671 | 673 | 'imgserv' => '$path/imgserv-wrapper -i svg -o png -w$width $input $output', |
| 674 | + 'ImagickExt' => array( 'SvgHandler::rasterizeImagickExt' ), |
672 | 675 | ); |
673 | 676 | /** Pick a converter defined in $wgSVGConverters */ |
674 | 677 | $wgSVGConverter = 'ImageMagick'; |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -103,6 +103,8 @@ |
104 | 104 | * When $wgAllowMicrodataAttributes is true, all itemtypes are allowed, not just |
105 | 105 | the three that were defined in the original specification. |
106 | 106 | * (bug 14706) Added support for the Imagick PHP extension. |
| 107 | +* (bug 18691) Added support for SVG rasterization using the Imagick PHP |
| 108 | + extension |
107 | 109 | |
108 | 110 | === Bug fixes in 1.18 === |
109 | 111 | * (bug 23119) WikiError class and subclasses are now marked as deprecated |