Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php |
— | — | @@ -276,7 +276,7 @@ |
277 | 277 | */ |
278 | 278 | function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) { |
279 | 279 | global $wgImageMagickConvertCommand, $wgTiffMaxEmbedFileResolution, |
280 | | - $wgTiffUseVips, $wgTiffVipsCommand; |
| 280 | + $wgTiffUseVips, $wgTiffVipsCommand, $wgMaxImageArea; |
281 | 281 | |
282 | 282 | $meta = $this->getMetaArray( $image ); |
283 | 283 | $errors = PagedTiffHandler::getMetadataErrors( $meta ); |
— | — | @@ -325,12 +325,33 @@ |
326 | 326 | return $this->doThumbError( $params, 'thumbnail_dest_directory' ); |
327 | 327 | |
328 | 328 | if ( $wgTiffUseVips ) { |
329 | | - // tested in Linux |
330 | | - $cmd = wfEscapeShellArg( $wgTiffVipsCommand ); |
331 | | - $cmd .= ' im_resize_linear "' . wfEscapeShellArg( $srcPath ) . ':' . ( $page - 1 ) . '" '; |
332 | | - $cmd .= wfEscapeShellArg( $dstPath ); |
333 | | - $cmd .= " {$width} {$height} 2>&1"; |
| 329 | + $pagesize = PagedTiffImage::getPageSize($meta, $page); |
| 330 | + if ( !$pagesize ) { |
| 331 | + return $this->doThumbError( $params, 'tiff_no_metadata' ); |
| 332 | + } |
| 333 | + |
| 334 | + // Shrink factors must be > 1. |
| 335 | + if ( ( $pagesize['width'] > $width ) && ( $pagesize['height'] > $height ) ) { |
| 336 | + $xfac = $pagesize['width'] / $width; |
| 337 | + $yfac = $pagesize['height'] / $height; |
| 338 | + // tested in Linux and Windows |
| 339 | + $cmd = wfEscapeShellArg( $wgTiffVipsCommand ); |
| 340 | + $cmd .= ' im_shrink "' . wfEscapeShellArg( $srcPath ) . ':' . ( $page - 1 ) . '" '; |
| 341 | + $cmd .= wfEscapeShellArg( $dstPath ); |
| 342 | + $cmd .= " {$xfac} {$yfac} 2>&1"; |
| 343 | + } else { |
| 344 | + // tested in Linux and Windows |
| 345 | + $cmd = wfEscapeShellArg( $wgTiffVipsCommand ); |
| 346 | + $cmd .= ' im_resize_linear "' . wfEscapeShellArg( $srcPath ) . ':' . ( $page - 1 ) . '" '; |
| 347 | + $cmd .= wfEscapeShellArg( $dstPath ); |
| 348 | + $cmd .= " {$width} {$height} 2>&1"; |
| 349 | + } |
334 | 350 | } else { |
| 351 | + if ( ( $width * $height ) > $wgMaxImageArea ) |
| 352 | + return $this->doThumbError( $params, 'tiff_targetfile_too_large' ); |
| 353 | + if ( isset( $meta['page_data'][$page]['pixels'] ) |
| 354 | + && $meta['page_data'][$page]['pixels'] > $wgMaxImageArea ) |
| 355 | + return $this->doThumbError( $params, 'tiff_sourcefile_too_large' ); |
335 | 356 | $cmd = wfEscapeShellArg( $wgImageMagickConvertCommand ); |
336 | 357 | $cmd .= " " . wfEscapeShellArg( $srcPath ) . "[" . ( $page - 1 ) . "]"; |
337 | 358 | $cmd .= " -depth 8 -resize {$width} "; |