*/
class BitmapHandler extends ImageHandler {
/**
- * @param $image File
+ * @param File $image
* @param array $params Transform parameters. Entries with the keys 'width'
* and 'height' are the respective screen width and height, while the keys
* 'physicalWidth' and 'physicalHeight' indicate the thumbnail dimensions.
# Check if the file is smaller than the maximum image area for thumbnailing
$checkImageAreaHookResult = null;
- wfRunHooks( 'BitmapHandlerCheckImageArea', array( $image, &$params, &$checkImageAreaHookResult ) );
+ wfRunHooks(
+ 'BitmapHandlerCheckImageArea',
+ array( $image, &$params, &$checkImageAreaHookResult )
+ );
+
if ( is_null( $checkImageAreaHookResult ) ) {
global $wgMaxImageArea;
if ( $srcWidth * $srcHeight > $wgMaxImageArea
&& !( $image->getMimeType() == 'image/jpeg'
- && self::getScalerType( false, false ) == 'im' )
+ && self::getScalerType( false, false ) == 'im' )
) {
# Only ImageMagick can efficiently downsize jpg images without loading
# the entire file in memory
}
/**
- * @param $image File
- * @param $dstPath
- * @param $dstUrl
- * @param $params
+ * @param File $image
+ * @param string $dstPath
+ * @param string $dstUrl
+ * @param array $params
* @param int $flags
* @return MediaTransformError|ThumbnailImage|TransformParameterError
*/
# Determine scaler type
$scaler = self::getScalerType( $dstPath );
- wfDebug( __METHOD__ . ": creating {$scalerParams['physicalDimensions']} thumbnail at $dstPath using scaler $scaler\n" );
+ wfDebug( __METHOD__ . ": creating {$scalerParams['physicalDimensions']} " .
+ "thumbnail at $dstPath using scaler $scaler\n" );
if ( !$image->mustRender() &&
$scalerParams['physicalWidth'] == $scalerParams['srcWidth']
# Try to make a target path for the thumbnail
if ( !wfMkdirParents( dirname( $dstPath ), null, __METHOD__ ) ) {
- wfDebug( __METHOD__ . ": Unable to create thumbnail destination directory, falling back to client scaling\n" );
+ wfDebug( __METHOD__ . ": Unable to create thumbnail destination " .
+ "directory, falling back to client scaling\n" );
return $this->getClientScalingThumbnailImage( $image, $scalerParams );
}
wfHostname(), $image->getName() ) );
return new MediaTransformError( 'thumbnail_error',
- $scalerParams['clientWidth'], $scalerParams['clientHeight'] );
+ $scalerParams['clientWidth'], $scalerParams['clientHeight'],
+ wfMessage( 'filemissing' )->text()
+ );
}
# Try a hook
switch ( $scaler ) {
case 'hookaborted':
# Handled by the hook above
+ /** @var MediaTransformOutput $mto */
$err = $mto->isError() ? $mto : false;
break;
case 'im':
} elseif ( $removed ) {
# Thumbnail was zero-byte and had to be removed
return new MediaTransformError( 'thumbnail_error',
- $scalerParams['clientWidth'], $scalerParams['clientHeight'] );
+ $scalerParams['clientWidth'], $scalerParams['clientHeight'],
+ wfMessage( 'unknown-error' )->text()
+ );
} elseif ( $mto ) {
return $mto;
} else {
* Returns which scaler type should be used. Creates parent directories
* for $dstPath and returns 'client' on error
*
- * @return string client,im,custom,gd
+ * @param string $dstPath
+ * @param bool $checkDstPath
+ * @return string One of client, im, custom, gd, imext
*/
protected static function getScalerType( $dstPath, $checkDstPath = true ) {
global $wgUseImageResize, $wgUseImageMagick, $wgCustomConvertCommand;
* Get a ThumbnailImage that respresents an image that will be scaled
* client side
*
- * @param $image File File associated with this thumbnail
+ * @param File $image File associated with this thumbnail
* @param array $scalerParams Array with scaler params
* @return ThumbnailImage
*
- * @todo fixme: no rotation support
+ * @todo FIXME: No rotation support
*/
protected function getClientScalingThumbnailImage( $image, $scalerParams ) {
$params = array(
/**
* Transform an image using ImageMagick
*
- * @param $image File File associated with this thumbnail
+ * @param File $image File associated with this thumbnail
* @param array $params Array with scaler params
*
* @return MediaTransformError Error object if error occurred, false (=no error) otherwise
if ( $retval !== 0 ) {
$this->logErrorForExternalProcess( $retval, $err, $cmd );
- return $this->getMediaTransformError( $params, $err );
+ return $this->getMediaTransformError( $params, "$err\nError code: $retval" );
}
return false; # No error
/**
* Transform an image using the Imagick PHP extension
*
- * @param $image File File associated with this thumbnail
+ * @param File $image File associated with this thumbnail
* @param array $params Array with scaler params
*
* @return MediaTransformError Error object if error occurred, false (=no error) otherwise
/**
* Transform an image using a custom command
*
- * @param $image File File associated with this thumbnail
+ * @param File $image File associated with this thumbnail
* @param array $params Array with scaler params
*
* @return MediaTransformError Error object if error occurred, false (=no error) otherwise
return false; # No error
}
- /**
- * Log an error that occurred in an external process
- *
- * @param $retval int
- * @param $err int
- * @param $cmd string
- */
- protected function logErrorForExternalProcess( $retval, $err, $cmd ) {
- wfDebugLog( 'thumbnail',
- sprintf( 'thumbnail failed on %s: error %d "%s" from "%s"',
- wfHostname(), $retval, trim( $err ), $cmd ) );
- }
-
/**
* Get a MediaTransformError with error 'thumbnail_error'
*
/**
* Transform an image using the built in GD library
*
- * @param $image File File associated with this thumbnail
+ * @param File $image File associated with this thumbnail
* @param array $params Array with scaler params
*
* @return MediaTransformError Error object if error occurred, false (=no error) otherwise
$typemap = array(
'image/gif' => array( 'imagecreatefromgif', 'palette', 'imagegif' ),
- 'image/jpeg' => array( 'imagecreatefromjpeg', 'truecolor', array( __CLASS__, 'imageJpegWrapper' ) ),
+ 'image/jpeg' => array( 'imagecreatefromjpeg', 'truecolor',
+ array( __CLASS__, 'imageJpegWrapper' ) ),
'image/png' => array( 'imagecreatefrompng', 'bits', 'imagepng' ),
'image/vnd.wap.wbmp' => array( 'imagecreatefromwbmp', 'palette', 'imagewbmp' ),
'image/xbm' => array( 'imagecreatefromxbm', 'palette', 'imagexbm' ),
/**
* Escape a string for ImageMagick's property input (e.g. -set -comment)
* See InterpretImageProperties() in magick/property.c
- * @return mixed|string
+ * @param string $s
+ * @return string
*/
function escapeMagickProperty( $s ) {
// Double the backslashes
/**
* Escape a string for ImageMagick's output filename. See
* InterpretImageFilename() in magick/image.c.
+ * @param string $path The file path
+ * @param bool|string $scene The scene specification, or false if there is none
* @return string
*/
function escapeMagickOutput( $path, $scene = false ) {
* Retrieve the version of the installed ImageMagick
* You can use PHPs version_compare() to use this value
* Value is cached for one hour.
- * @return String representing the IM version.
+ * @return string Representing the IM version.
*/
protected function getMagickVersion() {
global $wgMemc;
}
/**
- * @param $file File
+ * @see $wgEnableAutoRotation
+ * @return bool Whether auto rotation is enabled
+ */
+ public static function autoRotateEnabled() {
+ global $wgEnableAutoRotation;
+
+ if ( $wgEnableAutoRotation === null ) {
+ // Only enable auto-rotation when the bitmap handler can rotate
+ $wgEnableAutoRotation = BitmapHandler::canRotate();
+ }
+
+ return $wgEnableAutoRotation;
+ }
+
+ /**
+ * @param File $file
* @param array $params Rotate parameters.
- * 'rotation' clockwise rotation in degrees, allowed are multiples of 90
+ * 'rotation' clockwise rotation in degrees, allowed are multiples of 90
* @since 1.21
* @return bool
*/
wfDebug( __METHOD__ . ": running ImageMagick: $cmd\n" );
wfProfileIn( 'convert' );
$retval = 0;
+ // @todo FIXME: Undefined variable %env
$err = wfShellExecWithStderr( $cmd, $retval, $env );
wfProfileOut( 'convert' );
if ( $retval !== 0 ) {
* Rerurns whether the file needs to be rendered. Returns true if the
* file requires rotation and we are able to rotate it.
*
- * @param $file File
+ * @param File $file
* @return bool
*/
public function mustRender( $file ) {