Index: trunk/extensions/VipsScaler/VipsScaler.php |
— | — | @@ -32,6 +32,7 @@ |
33 | 33 | $wgExtensionMessagesFiles['VipsScaler'] = "$dir/VipsScaler.i18n.php"; |
34 | 34 | |
35 | 35 | $wgHooks['BitmapHandlerTransform'][] = 'VipsScaler::onTransform'; |
| 36 | +$wgHooks['BitmapHandlerCheckImageArea'][] = 'VipsScaler::onBitmapHandlerCheckImageArea'; |
36 | 37 | |
37 | 38 | # Download vips from http://www.vips.ecs.soton.ac.uk/ |
38 | 39 | $wgVipsCommand = 'vips'; |
Index: trunk/extensions/VipsScaler/VipsScaler_body.php |
— | — | @@ -14,8 +14,10 @@ |
15 | 15 | $options = self::getHandlerOptions( $handler, $file, $params ); |
16 | 16 | if ( !$options ) { |
17 | 17 | return true; |
18 | | - } |
| 18 | + } |
19 | 19 | |
| 20 | + wfDebug( __METHOD__ . ': scaling ' . $file->getName() . " using vips\n" ); |
| 21 | + |
20 | 22 | $vipsCommands = self::makeCommands( $handler, $file, $params, $options ); |
21 | 23 | if ( count( $vipsCommands ) == 0 ) { |
22 | 24 | return true; |
— | — | @@ -46,7 +48,7 @@ |
47 | 49 | } |
48 | 50 | |
49 | 51 | # Set comment |
50 | | - if ( !empty( $options['setcomment'] ) && isset( $params['comment'] ) ) { |
| 52 | + if ( !empty( $options['setcomment'] ) && !empty( $params['comment'] ) ) { |
51 | 53 | self::setJpegComment( $params['dstPath'], $params['comment'] ); |
52 | 54 | } |
53 | 55 | |
— | — | @@ -182,7 +184,7 @@ |
183 | 185 | continue; |
184 | 186 | } |
185 | 187 | |
186 | | - $area = $handler->getImageArea( $file, $params['srcWidth'], $params['srcHeight'] ); |
| 188 | + $area = $handler->getImageArea( $file ); |
187 | 189 | if ( isset( $condition['minArea'] ) && $area < $condition['minArea'] ) { |
188 | 190 | continue; |
189 | 191 | } |
— | — | @@ -190,7 +192,7 @@ |
191 | 193 | continue; |
192 | 194 | } |
193 | 195 | |
194 | | - $shrinkFactor = $params['srcWidth'] / ( |
| 196 | + $shrinkFactor = $file->getWidth() / ( |
195 | 197 | ( ( $handler->getRotation( $file ) % 180 ) == 90 ) ? |
196 | 198 | $params['physicalHeight'] : $params['physicalWidth'] ); |
197 | 199 | if ( isset( $condition['minShrinkFactor'] ) && |
— | — | @@ -240,6 +242,24 @@ |
241 | 243 | } |
242 | 244 | } |
243 | 245 | |
| 246 | + /** |
| 247 | + * Hook to BitmapHandlerCheckImageArea. Will set $result to true if the |
| 248 | + * file will by handled by VipsScaler. |
| 249 | + * |
| 250 | + * @param File $file |
| 251 | + * @param array &$params |
| 252 | + * @param mixed &$result |
| 253 | + * @return bool |
| 254 | + */ |
| 255 | + public static function onBitmapHandlerCheckImageArea( $file, &$params, &$result ) { |
| 256 | + if ( self::getHandlerOptions( $file->getHandler(), $file, $params ) !== false ) { |
| 257 | + wfDebug( __METHOD__ . ": Overriding $wgMaxImageAre\n" ); |
| 258 | + $result = true; |
| 259 | + return false; |
| 260 | + } |
| 261 | + return true; |
| 262 | + } |
| 263 | + |
244 | 264 | |
245 | 265 | } |
246 | 266 | |