Brian Wolff has uploaded a new change for review.
https://gerrit.wikimedia.org/r/86413
Change subject: Make PagedTiffHandler work with VipsScaler.
......................................................................
Make PagedTiffHandler work with VipsScaler.
PagedTiffHandler has basic support for VipsScaler, but it's not
as flexible as we probably want. In particular it looks like
the commons community is going to want sharpening enabled for
tiffs. On top of that, I think its good to keep all the vips code
together.
In order for this to work it needs I63f2be2a6f31 from core (Changing
some methods from BitmapHandler to the base class). I also directly
added getMediaTransformError to this class, as that didn't seem like
an appropriate method for MediaHandler.
I wasn't sure if I should use the same hook or a different hook. I
opted for the same, since the hooks are doing the exact same thing,
and if you don't have PagedTiffHandler installed, this hook would get
called when rendering tiff files, so its not like subscribers to this
hook have any right to be shocked by a tiff file.
Bug: 52045
Change-Id: I1b9a77a4a56eeb6535fa46d30b2051841389951c
---
M PagedTiffHandler_body.php
1 file changed, 54 insertions(+), 11 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PagedTiffHandler
refs/changes/13/86413/1
diff --git a/PagedTiffHandler_body.php b/PagedTiffHandler_body.php
index efbcc05..ab1331c 100644
--- a/PagedTiffHandler_body.php
+++ b/PagedTiffHandler_body.php
@@ -333,11 +333,42 @@
return $this->doThumbError( $params, $error );
}
+ // Get local copy source for shell scripts
+ $srcPath = $image->getLocalRefPath();
+
+ // Allow extensions to override thumbnail command.
+ $scalerParams = array(
+ # The size to which the image will be resized
+ 'physicalWidth' => $params['physicalWidth'],
+ 'physicalHeight' => $params['physicalHeight'],
+ 'physicalDimensions' =>
"{$params['physicalWidth']}x{$params['physicalHeight']}",
+ # The size of the image on the page
+ 'clientWidth' => $params['width'],
+ 'clientHeight' => $params['height'],
+ # Comment to maybe be added to exif
+ 'comment' => isset( $params['descriptionUrl'] ) ?
+ "File source: {$params['descriptionUrl']}" : '',
+ # Properties of the original image
+ 'srcWidth' => $image->getWidth(),
+ 'srcHeight' => $image->getHeight(),
+ 'srcPath' => $srcPath,
+ 'page' => $page,
+ 'mimeType' => $image->getMimeType(),
+ 'dstPath' => $dstPath,
+ 'dstUrl' => $dstUrl,
+ );
+
+ $mto = null;
+ wfRunHooks( 'BitmapHandlerTransform', array( $this, $image,
&$scalerParams, &$mto ) );
+ if ( !is_null( $mto ) ) {
+ // A hook took over.
+ wfDebug( __METHOD__ . ': Overriden by
BitmapHandlerTransform hook' );
+ return $mto;
+ }
+
if ( !wfMkdirParents( dirname( $dstPath ), null, __METHOD__ ) )
return $this->doThumbError( $params,
'thumbnail_dest_directory' );
- // Get local copy source for shell scripts
- $srcPath = $image->getLocalRefPath();
if ( $wgTiffUseVips ) {
$pagesize = PagedTiffImage::getPageSize($meta, $page);
@@ -391,7 +422,7 @@
if ( $retval != 0 || $removed ) {
wfDebugLog( 'thumbnail', "thumbnail failed on " .
wfHostname() .
"; error $retval \"$err\" from \"$cmd\"" );
- return new MediaTransformError( 'thumbnail_error',
$width, $height, $err );
+ return $this->getMediaTransformError( $params, $err );
} else {
return new ThumbnailImage( $image, $dstUrl, $width,
$height, $dstPath, $page );
}
@@ -475,6 +506,7 @@
protected function doThumbError( $params, $msg ) {
global $wgUser, $wgThumbLimits;
+ $errorParams = array();
if ( empty( $params['width'] ) ) {
// no usable width/height in the parameter array
// only happens if we don't have image meta-data, and no
@@ -482,21 +514,19 @@
// we need to pick *some* size, and the preferred
// thumbnail size seems sane.
$sz = $wgUser->getOption( 'thumbsize' );
- $width = $wgThumbLimits[ $sz ];
- $height = $width; // we don't have a height or aspect
ratio. make it square.
+ $errorParams['width'] = $wgThumbLimits[ $sz ];
+ $errorParams['height'] = $width; // we don't have a
height or aspect ratio. make it square.
} else {
- $width = intval( $params['width'] );
+ $errorParams['width'] = intval( $params['width'] );
if ( !empty( $params['height'] ) ) {
- $height = intval( $params['height'] );
+ $errorParams['height'] = intval(
$params['height'] );
} else {
- $height = $width; // we don't have a height or
aspect ratio. make it square.
+ $errorParams['width'] = $errorParams['height'];
// we don't have a height or aspect ratio. make it square.
}
}
-
- return new MediaTransformError( 'thumbnail_error',
- $width, $height, wfMessage( $msg )->text() );
+ return $this->getMediaTransformError( $errorParams, wfMessage(
$msg )->text() );
}
/**
@@ -752,4 +782,17 @@
}
return true; // pass through to next handler
}
+
+ /**
+ * Get a MediaTransformError with error 'thumbnail_error'. Copied from
BitmapHandler
+ *
+ * @param array $params Parameter array as passed to the transform*
functions
+ * @param string $errMsg Error message
+ * @return MediaTransformError
+ */
+ public function getMediaTransformError( $params, $errMsg ) {
+ return new MediaTransformError( 'thumbnail_error',
$params['clientWidth'],
+ $params['clientHeight'], $errMsg );
+ }
+
}
--
To view, visit https://gerrit.wikimedia.org/r/86413
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1b9a77a4a56eeb6535fa46d30b2051841389951c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PagedTiffHandler
Gerrit-Branch: master
Gerrit-Owner: Brian Wolff <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits