http://www.mediawiki.org/wiki/Special:Code/MediaWiki/69422

Revision: 69422
Author:   mglaser
Date:     2010-07-16 11:41:51 +0000 (Fri, 16 Jul 2010)

Log Message:
-----------
* use wgMaxImageArea when resizing with imagemagic
* use im_shrink when rendering with vips
* removed selenium_copy_to_mediawiki_root, since it has been integrated into 
maintenance/tests/selenium

Modified Paths:
--------------
    trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php

Removed Paths:
-------------
    trunk/extensions/PagedTiffHandler/selenium_copy_to_mediawiki_root/

Modified: trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php
===================================================================
--- trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php 2010-07-16 
11:40:19 UTC (rev 69421)
+++ trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php 2010-07-16 
11:41:51 UTC (rev 69422)
@@ -276,7 +276,7 @@
         */
        function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
                global $wgImageMagickConvertCommand, 
$wgTiffMaxEmbedFileResolution, 
-                       $wgTiffUseVips, $wgTiffVipsCommand;
+                       $wgTiffUseVips, $wgTiffVipsCommand, $wgMaxImageArea;
 
                $meta = $this->getMetaArray( $image );
                $errors = PagedTiffHandler::getMetadataErrors( $meta );
@@ -325,12 +325,33 @@
                        return $this->doThumbError( $params, 
'thumbnail_dest_directory' );
 
                if ( $wgTiffUseVips ) {
-                       // tested in Linux
-                       $cmd = wfEscapeShellArg( $wgTiffVipsCommand );
-                       $cmd .= ' im_resize_linear "' . wfEscapeShellArg( 
$srcPath ) . ':' . ( $page - 1 ) . '" ';
-                       $cmd .= wfEscapeShellArg( $dstPath );
-                       $cmd .= " {$width} {$height} 2>&1";
+                       $pagesize = PagedTiffImage::getPageSize($meta, $page);
+                       if ( !$pagesize ) {
+                               return $this->doThumbError( $params, 
'tiff_no_metadata' );
+                       }
+                       
+                       // Shrink factors must be > 1.
+                       if ( ( $pagesize['width'] > $width ) && ( 
$pagesize['height'] > $height ) ) {
+                               $xfac = $pagesize['width'] / $width;
+                               $yfac = $pagesize['height'] / $height;
+                               // tested in Linux and Windows
+                               $cmd = wfEscapeShellArg( $wgTiffVipsCommand );
+                               $cmd .= ' im_shrink "' . wfEscapeShellArg( 
$srcPath ) . ':' . ( $page - 1 ) . '" ';
+                               $cmd .= wfEscapeShellArg( $dstPath );
+                               $cmd .= " {$xfac} {$yfac} 2>&1";
+                       } else {
+                               // tested in Linux and Windows
+                               $cmd = wfEscapeShellArg( $wgTiffVipsCommand );
+                               $cmd .= ' im_resize_linear "' . 
wfEscapeShellArg( $srcPath ) . ':' . ( $page - 1 ) . '" ';
+                               $cmd .= wfEscapeShellArg( $dstPath );
+                               $cmd .= " {$width} {$height} 2>&1";
+                       }
                } else {
+                       if ( ( $width * $height ) > $wgMaxImageArea )
+                               return $this->doThumbError( $params, 
'tiff_targetfile_too_large' );
+                       if ( isset( $meta['page_data'][$page]['pixels'] ) 
+                                       && $meta['page_data'][$page]['pixels'] 
> $wgMaxImageArea )
+                               return $this->doThumbError( $params, 
'tiff_sourcefile_too_large' );
                        $cmd = wfEscapeShellArg( $wgImageMagickConvertCommand );
                        $cmd .= " " . wfEscapeShellArg( $srcPath ) . "[" . ( 
$page - 1 ) . "]";
                        $cmd .= " -depth 8 -resize {$width} ";



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to