Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Image_Driver_Abstract Class Reference

Abstract class for image drivers. More...

Inheritance diagram for P4Cms_Image_Driver_Abstract:
P4Cms_Image_Driver_Interface P4Cms_Image_Driver_Gd P4Cms_Image_Driver_Imagick

List of all members.

Public Member Functions

 __construct ()
 Deny creating an instance if required extension (if set) is not loaded.
 getImageSize ()
 Return the image dimensions.
 transform ($transform, $args=array())
 Apply the given transformation.

Static Public Member Functions

static getRequiredExtension ()
 Return php extension that must be installed to make the driver work or null if no extension is needed.
static getSupportedTransforms ()
 Return list of supported transformations.
static isSupportedTransform ($transform)
 Determine if the given transformation is supported by this driver.

Protected Member Functions

 _getImageHeight ()
 Return image height in pixels.
 _getImageWidth ()
 Return image width in pixels.

Static Protected Attributes

static $_requiredExtension = null
static $_supportedTransforms = array()

Detailed Description

Abstract class for image drivers.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Constructor & Destructor Documentation

P4Cms_Image_Driver_Abstract::__construct ( )

Deny creating an instance if required extension (if set) is not loaded.

Exceptions:
P4Cms_Image_Exceptionif the required extension is not loaded
    {
        $extension = static::$_requiredExtension;
        if ($extension && !extension_loaded($extension)) {
            throw new P4Cms_Image_Exception(
                "Cannot create image driver: required extension '"
                . $extension . "' is not loaded."
            );
        }
    }

Member Function Documentation

P4Cms_Image_Driver_Abstract::_getImageHeight ( ) [abstract, protected]

Return image height in pixels.

Returns:
int image height in pixels

Reimplemented in P4Cms_Image_Driver_Gd, and P4Cms_Image_Driver_Imagick.

P4Cms_Image_Driver_Abstract::_getImageWidth ( ) [abstract, protected]

Return image width in pixels.

Returns:
int image width in pixels

Reimplemented in P4Cms_Image_Driver_Gd, and P4Cms_Image_Driver_Imagick.

P4Cms_Image_Driver_Abstract::getImageSize ( )

Return the image dimensions.

Returns:
array associative array with image width and height in pixels

Implements P4Cms_Image_Driver_Interface.

    {
        // cannot get image size if there are no image data
        if (!$this->hasData()) {
            throw new P4Cms_Image_Exception(
                "Can not get image size: no image data were set."
            );
        }

        return array(
            'width'  => $this->_getImageWidth(),
            'height' => $this->_getImageheight()
        );
    }
static P4Cms_Image_Driver_Abstract::getRequiredExtension ( ) [static]

Return php extension that must be installed to make the driver work or null if no extension is needed.

Returns:
string|null php extension required by the driver or null if no extension required
static P4Cms_Image_Driver_Abstract::getSupportedTransforms ( ) [static]

Return list of supported transformations.

Returns:
array a list of the supported transform operations

Implements P4Cms_Image_Driver_Interface.

static P4Cms_Image_Driver_Abstract::isSupportedTransform ( transform) [static]

Determine if the given transformation is supported by this driver.

Parameters:
string$transformthe transformation to check for
Returns:
boolean true if the transformation supported by the current driver, false otherwise

Implements P4Cms_Image_Driver_Interface.

    {
        return in_array($transform, static::getSupportedTransforms());
    }
P4Cms_Image_Driver_Abstract::transform ( transform,
args = array() 
)

Apply the given transformation.

Parameters:
string$transformname of the transformation
array$argsoptional - transformation arguments
Exceptions:
P4Cms_Image_Exceptionif given transformation is not supported

Implements P4Cms_Image_Driver_Interface.

    {
        // throw an exception if transformation is not supported
        if (!static::isSupportedTransform($transform)) {
            throw new P4Cms_Image_Exception("Transformation '$transform' is not supported.");
        }

        // cannot transform if there are no image data
        if (!$this->hasData()) {
            throw new P4Cms_Image_Exception(
                "Cannot do '" . $transform . "': image contains no data."
            );
        }

        // assemble callback function to apply given transform on the image data
        $callback = array('static', '_' . strtolower($transform));
        if (!is_callable($callback)) {
            throw new P4Cms_Image_Exception("Transform '$transform' is not implemented.");
        }
        call_user_func_array($callback, $args);
    }

Member Data Documentation

P4Cms_Image_Driver_Abstract::$_requiredExtension = null [static, protected]
P4Cms_Image_Driver_Abstract::$_supportedTransforms = array() [static, protected]

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