MediaWiki  REL1_24
TransformationalImageHandler Class Reference

Handler for images that need to be transformed. More...

Inheritance diagram for TransformationalImageHandler:
Collaboration diagram for TransformationalImageHandler:

List of all members.

Public Member Functions

 autoRotateEnabled ()
 Should we automatically rotate an image based on exif.
 canRotate ()
 Returns whether the current scaler supports rotation.
 doTransform ($image, $dstPath, $dstUrl, $params, $flags=0)
 Create a thumbnail.
 escapeMagickInput ($path, $scene=false)
 Escape a string for ImageMagick's input filenames.
 escapeMagickOutput ($path, $scene=false)
 Escape a string for ImageMagick's output filename.
 escapeMagickProperty ($s)
 Escape a string for ImageMagick's property input (e.g.
 extractPreRotationDimensions ($params, $rotation)
 Extracts the width/height if the image will be scaled before rotating.
 getMediaTransformError ($params, $errMsg)
 Get a MediaTransformError with error 'thumbnail_error'.
 mustRender ($file)
 Returns whether the file needs to be rendered.
 normaliseParams ($image, &$params)
 rotate ($file, $params)
 Rotate a thumbnail.

Protected Member Functions

 escapeMagickPath ($path, $scene=false)
 Armour a string against ImageMagick's GetPathComponent().
 getClientScalingThumbnailImage ($image, $scalerParams)
 Get a ThumbnailImage that respresents an image that will be scaled client side.
 getMagickVersion ()
 Retrieve the version of the installed ImageMagick You can use PHPs version_compare() to use this value Value is cached for one hour.
 getScalerType ($dstPath, $checkDstPath=true)
 Returns what sort of scaler type should be used.
 getThumbnailSource ($file, $params)
 Get the source file for the transform.
 transformCustom ($image, $params)
 Transform an image using a custom command.
 transformGd ($image, $params)
 Transform an image using the built in GD library.
 transformImageMagick ($image, $params)
 Transform an image using ImageMagick.
 transformImageMagickExt ($image, $params)
 Transform an image using the Imagick PHP extension.

Detailed Description

Handler for images that need to be transformed.

Since:
1.24

Definition at line 35 of file TransformationalImageHandler.php.


Member Function Documentation

Should we automatically rotate an image based on exif.

Since:
1.24 No longer static
See also:
$wgEnableAutoRotation
Returns:
bool Whether auto rotation is enabled

Reimplemented in BitmapHandler.

Definition at line 563 of file TransformationalImageHandler.php.

Returns whether the current scaler supports rotation.

Since:
1.24 No longer static
Returns:
bool

Reimplemented from MediaHandler.

Reimplemented in BitmapHandler.

Definition at line 552 of file TransformationalImageHandler.php.

Referenced by mustRender().

TransformationalImageHandler::doTransform ( image,
dstPath,
dstUrl,
params,
flags = 0 
)

Create a thumbnail.

This sets up various parameters, and then calls a helper method based on $this->getScalerType in order to scale the image.

Parameters:
File$image
string$dstPath
string$dstUrl
array$params
int$flags
Returns:
MediaTransformError|ThumbnailImage|TransformParameterError

Reimplemented from MediaHandler.

Reimplemented in BitmapHandler_ClientOnly, and MockBitmapHandler.

Definition at line 128 of file TransformationalImageHandler.php.

References $flags, $params, array(), as, getClientScalingThumbnailImage(), getScalerType(), getThumbnailSource(), normaliseParams(), of, on, page, MediaHandler\removeBadFile(), text, transformCustom(), transformGd(), transformImageMagick(), transformImageMagickExt(), wfDebug(), wfDebugLog(), wfHostname(), wfMessage(), wfMkdirParents(), wfRunHooks(), and will.

Escape a string for ImageMagick's input filenames.

See ExpandFilenames() and GetPathComponent() in magick/utility.c.

This won't work with an initial ~ or @, so input files should be prefixed with the directory name.

Glob character unescaping is broken in ImageMagick before 6.6.1-5, but it's broken in a way that doesn't involve trying to convert every file in a directory, so we're better off escaping and waiting for the bugfix to filter down to users.

Parameters:
string$pathThe file path
bool | string$sceneThe scene specification, or false if there is none
Exceptions:
MWException
Returns:
string

Definition at line 456 of file TransformationalImageHandler.php.

References $path, and escapeMagickPath().

Referenced by BitmapHandler\rotate(), and BitmapHandler\transformImageMagick().

Escape a string for ImageMagick's output filename.

See InterpretImageFilename() in magick/image.c.

Parameters:
string$pathThe file path
bool | string$sceneThe scene specification, or false if there is none
Returns:
string

Definition at line 476 of file TransformationalImageHandler.php.

References $path, and escapeMagickPath().

Referenced by BitmapHandler\rotate(), and BitmapHandler\transformImageMagick().

TransformationalImageHandler::escapeMagickPath ( path,
scene = false 
) [protected]

Armour a string against ImageMagick's GetPathComponent().

This is a helper function for escapeMagickInput() and escapeMagickOutput().

Parameters:
string$pathThe file path
bool | string$sceneThe scene specification, or false if there is none
Exceptions:
MWException
Returns:
string

Definition at line 491 of file TransformationalImageHandler.php.

References $path, and wfIsWindows().

Referenced by escapeMagickInput(), and escapeMagickOutput().

Escape a string for ImageMagick's property input (e.g.

-set -comment) See InterpretImageProperties() in magick/property.c

Parameters:
string$s
Returns:
string

Definition at line 426 of file TransformationalImageHandler.php.

References $s.

Referenced by BitmapHandler\transformImageMagick().

Extracts the width/height if the image will be scaled before rotating.

This will match the physical size/aspect ratio of the original image prior to application of the rotation -- so for a portrait image that's stored as raw landscape with 90-degress rotation, the resulting size will be wider than it is tall.

Parameters:
array$paramsParameters as returned by normaliseParams
int$rotationThe rotation angle that will be applied
Returns:
array ($width, $height) array

Definition at line 102 of file TransformationalImageHandler.php.

References $params, and array().

Referenced by BitmapHandler\transformGd(), BitmapHandler\transformImageMagick(), and BitmapHandler\transformImageMagickExt().

TransformationalImageHandler::getClientScalingThumbnailImage ( image,
scalerParams 
) [protected]

Get a ThumbnailImage that respresents an image that will be scaled client side.

Parameters:
File$imageFile associated with this thumbnail
array$scalerParamsArray with scaler params
Returns:
ThumbnailImage
Todo:
FIXME: No rotation support

Definition at line 343 of file TransformationalImageHandler.php.

References $params, and array().

Referenced by MockBitmapHandler\doClientImage(), and doTransform().

Retrieve the version of the installed ImageMagick You can use PHPs version_compare() to use this value Value is cached for one hour.

Returns:
string Representing the IM version.

Definition at line 522 of file TransformationalImageHandler.php.

References $cache, $matches, $retval, $wgMemc, global, wfDebug(), wfEscapeShellArg(), and wfShellExec().

Referenced by BitmapHandler\transformImageMagick().

Get a MediaTransformError with error 'thumbnail_error'.

Parameters:
array$paramsParameter array as passed to the transform* functions
string$errMsgError message
Returns:
MediaTransformError

Definition at line 401 of file TransformationalImageHandler.php.

References $params.

Referenced by BitmapHandler\transformCustom(), transformCustom(), BitmapHandler\transformGd(), transformGd(), BitmapHandler\transformImageMagick(), transformImageMagick(), BitmapHandler\transformImageMagickExt(), and transformImageMagickExt().

TransformationalImageHandler::getScalerType ( dstPath,
checkDstPath = true 
) [abstract, protected]

Returns what sort of scaler type should be used.

Values can be one of client, im, custom, gd, imext, or an array of object, method-name to call that specific method.

If specifying a custom scaler command with array( Obj, method ), the method in question should take 2 parameters, a File object, and a $scalerParams array with various options (See doTransform for what is in $scalerParams). On error it should return a MediaTransformError object. On success it should return false, and simply make sure the thumbnail file is located at $scalerParams['dstPath'].

If there is a problem with the output path, it returns "client" to do client side scaling.

Parameters:
string$dstPath
bool$checkDstPathCheck that $dstPath is valid
Returns:
string|Callable One of client, im, custom, gd, imext, or a Callable array.

Reimplemented in XCFHandler, and BitmapHandler.

Referenced by doTransform(), and normaliseParams().

TransformationalImageHandler::getThumbnailSource ( file,
params 
) [protected]

Get the source file for the transform.

Parameters:
$fileFile
$paramsArray
Returns:
Array Array with keys width, height and path.

Definition at line 306 of file TransformationalImageHandler.php.

References $file, and $params.

Referenced by doTransform().

Returns whether the file needs to be rendered.

Returns true if the file requires rotation and we are able to rotate it.

Parameters:
File$file
Returns:
bool

Reimplemented from MediaHandler.

Reimplemented in TiffHandler, XCFHandler, and BmpHandler.

Definition at line 590 of file TransformationalImageHandler.php.

References $file, canRotate(), and MediaHandler\getRotation().

TransformationalImageHandler::normaliseParams ( image,
&$  params 
)
Parameters:
File$image
array$paramsTransform 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.
Returns:
bool

Reimplemented from ImageHandler.

Reimplemented in BitmapHandler_ClientOnly, and JpegHandler.

Definition at line 43 of file TransformationalImageHandler.php.

References $params, array(), getScalerType(), global, and wfRunHooks().

Referenced by doTransform(), and BitmapScalingTest\testNormaliseParams().

TransformationalImageHandler::rotate ( file,
params 
)

Rotate a thumbnail.

This is a stub. See BitmapHandler::rotate.

Parameters:
File$file
array$paramsRotate parameters. 'rotation' clockwise rotation in degrees, allowed are multiples of 90
Since:
1.24 Is non-static. From 1.21 it was static
Returns:
bool

Reimplemented in BitmapHandler, and JpegHandler.

Definition at line 578 of file TransformationalImageHandler.php.

TransformationalImageHandler::transformCustom ( image,
params 
) [protected]

Transform an image using a custom command.

This is a stub method. The real method is in BitmapHander.

Parameters:
File$imageFile associated with this thumbnail
array$paramsArray with scaler params
Returns:
MediaTransformError Error object if error occurred, false (=no error) otherwise

Reimplemented in BitmapHandler.

Definition at line 390 of file TransformationalImageHandler.php.

References $params, and getMediaTransformError().

Referenced by doTransform().

TransformationalImageHandler::transformGd ( image,
params 
) [protected]

Transform an image using the built in GD library.

This is a stub method. The real method is in BitmapHander.

Parameters:
File$imageFile associated with this thumbnail
array$paramsArray with scaler params
Returns:
MediaTransformError Error object if error occurred, false (=no error) otherwise

Reimplemented in BitmapHandler.

Definition at line 416 of file TransformationalImageHandler.php.

References $params, and getMediaTransformError().

Referenced by doTransform().

TransformationalImageHandler::transformImageMagick ( image,
params 
) [protected]

Transform an image using ImageMagick.

This is a stub method. The real method is in BitmapHander.

Parameters:
File$imageFile associated with this thumbnail
array$paramsArray with scaler params
Returns:
MediaTransformError Error object if error occurred, false (=no error) otherwise

Reimplemented in BitmapHandler.

Definition at line 362 of file TransformationalImageHandler.php.

References $params, and getMediaTransformError().

Referenced by doTransform().

TransformationalImageHandler::transformImageMagickExt ( image,
params 
) [protected]

Transform an image using the Imagick PHP extension.

This is a stub method. The real method is in BitmapHander.

Parameters:
File$imageFile associated with this thumbnail
array$paramsArray with scaler params
Returns:
MediaTransformError Error object if error occurred, false (=no error) otherwise

Reimplemented in BitmapHandler.

Definition at line 376 of file TransformationalImageHandler.php.

References $params, and getMediaTransformError().

Referenced by doTransform().


The documentation for this class was generated from the following file: