Perforce Chronicle 2012.2/486814
API Documentation

P4Cms_Image_Driver_Imagick Class Reference

Implementation of P4Cms_Image_Driver_Interface using the 'imagick' extension. More...

Inheritance diagram for P4Cms_Image_Driver_Imagick:
P4Cms_Image_Driver_Abstract P4Cms_Image_Driver_Interface

List of all members.

Public Member Functions

 getData ($type=null)
 Return binary image data in the given format.
 hasData ()
 Check if there are image data to operate with.
 setData ($data=null)
 Set the image data.

Static Public Member Functions

static isSupportedType ($type)
 Check if given image type is supported.

Protected Member Functions

 _crop ($width=null, $height=null, $x=0, $y=0)
 Crop the image to the given size and position.
 _getImageHeight ()
 Return image height in pixels.
 _getImageWidth ()
 Return image width in pixels.
 _getImagick ()
 Return reference to the Imagick object hold by this class.
 _rotate ($degrees)
 Rotate the image.
 _scale ($width=null, $height=null)
 Scale the image to the given size.
 _sharpen ()
 Sharpens an image by blurring with the given radius and subtracting from the original with the deviation.

Static Protected Member Functions

static _getSupportedTypes ()
 Return list of supported image types.

Protected Attributes

 $_imagick = null

Static Protected Attributes

static $_requiredExtension = 'imagick'
static $_supportedTransforms

Detailed Description

Implementation of P4Cms_Image_Driver_Interface using the 'imagick' extension.

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

Member Function Documentation

P4Cms_Image_Driver_Imagick::_crop ( width = null,
height = null,
x = 0,
y = 0 
) [protected]

Crop the image to the given size and position.

Parameters:
int | null$widththe width in pixels
int | null$heightthe height in pixels
int$xthe x coordinate starting position from the left
int$ythe y coordinate starting position from the top
    {
        if (!$width || !$height) {
            throw new P4Cms_Image_Exception(
                'Both image width and height are required.'
            );
        }

        $this->_getImagick()->cropImage(
            $width,
            $height,
            $x,
            $y
        );
    }
P4Cms_Image_Driver_Imagick::_getImageHeight ( ) [protected]

Return image height in pixels.

Returns:
int image height in pixels

Reimplemented from P4Cms_Image_Driver_Abstract.

    {
        $geometry = $this->_getImagick()->getImageGeometry();
        return $geometry['height'];
    }
P4Cms_Image_Driver_Imagick::_getImageWidth ( ) [protected]

Return image width in pixels.

Returns:
int image width in pixels

Reimplemented from P4Cms_Image_Driver_Abstract.

    {
        $geometry = $this->_getImagick()->getImageGeometry();
        return $geometry['width'];
    }
P4Cms_Image_Driver_Imagick::_getImagick ( ) [protected]

Return reference to the Imagick object hold by this class.

If there is no reference to an existing Imagick object, it will create one and set the reference, so the next time reference to the same object will be returned.

Returns:
Imagick Imagick object referenced by this class
    {
        if (!$this->_imagick) {
            $this->_imagick = new Imagick;
        }
        return $this->_imagick;
    }
static P4Cms_Image_Driver_Imagick::_getSupportedTypes ( ) [static, protected]

Return list of supported image types.

Returns:
array list of supported image types
    {
        return Imagick::queryFormats();
    }
P4Cms_Image_Driver_Imagick::_rotate ( degrees) [protected]

Rotate the image.

Parameters:
float$degreesthe rotation angle
    {
        $this->_getImagick()->rotateImage(new ImagickPixel('none'), $degrees);
    }
P4Cms_Image_Driver_Imagick::_scale ( width = null,
height = null 
) [protected]

Scale the image to the given size.

Parameters:
int$widththe width in pixels
int$heightthe height in pixels
    {
        if (!$width && !$height) {
            throw new P4Cms_Image_Exception(
                'At least one of width or height is required.'
            );
        }

        $this->_getImagick()->resizeImage(
            $width,
            $height,
            Imagick::FILTER_LANCZOS,
            1
        );
    }
P4Cms_Image_Driver_Imagick::_sharpen ( ) [protected]

Sharpens an image by blurring with the given radius and subtracting from the original with the deviation.

The radius should be larger than the deviation. A radius of zero will let the driver pick a suitable value. see: http://en.wikipedia.org/wiki/Unsharp_masking

    {
        $this->_getImagick()->sharpenImage(0, 1);
    }
P4Cms_Image_Driver_Imagick::getData ( type = null)

Return binary image data in the given format.

Parameters:
string$typeoptional - the image format (will return image data in the same format as input if not provided)
Returns:
string|null binary image data or null if no image data were set

Implements P4Cms_Image_Driver_Interface.

    {
        // early exit if there are no image data
        if (!$this->hasData()) {
            return null;
        }

        // set output image type if specified
        if ($type) {
            if (!static::isSupportedType($type)) {
                throw new P4Cms_Image_Exception("Image type '$type' is not supported.");
            }
            $this->_getImagick()->setImageFormat($type);
        }

        return $this->_getImagick()->getImageBlob();
    }
P4Cms_Image_Driver_Imagick::hasData ( )

Check if there are image data to operate with.

Returns:
bool true if there has been image data set, false otherwise.

Implements P4Cms_Image_Driver_Interface.

    {
        return $this->_imagick !== null;
    }
static P4Cms_Image_Driver_Imagick::isSupportedType ( type) [static]

Check if given image type is supported.

Parameters:
string$typeimage type to check for
Returns:
bool true if given image type is supported, false otherwise

Implements P4Cms_Image_Driver_Interface.

    {
        // get list of supported image types, normalized to lowercase
        $types = array_map('strtolower', static::_getSupportedTypes());

        return in_array(strtolower($type), $types);
    }
P4Cms_Image_Driver_Imagick::setData ( data = null)

Set the image data.

Parameters:
string | null$dataoptional - image data
Returns:
P4Cms_Image_Driver_Imagick provides fluent interface

Implements P4Cms_Image_Driver_Interface.

    {
        if ($data) {
            $this->_getImagick()->readImageBlob($data);
        } else {
            $this->_imagick = null;
        }
        return $this;
    }

Member Data Documentation

P4Cms_Image_Driver_Imagick::$_imagick = null [protected]
P4Cms_Image_Driver_Imagick::$_requiredExtension = 'imagick' [static, protected]

Reimplemented from P4Cms_Image_Driver_Abstract.

P4Cms_Image_Driver_Imagick::$_supportedTransforms [static, protected]
Initial value:
 array(
        'scale',
        'sharpen',
        'crop',
        'rotate'
    )

Reimplemented from P4Cms_Image_Driver_Abstract.


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