Perforce Chronicle 2012.2/486814
API Documentation
|
Implementation of P4Cms_Image_Driver_Interface using the 'imagick' extension. More...
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 |
Implementation of P4Cms_Image_Driver_Interface using the 'imagick' extension.
P4Cms_Image_Driver_Imagick::_crop | ( | $ | width = null , |
$ | height = null , |
||
$ | x = 0 , |
||
$ | y = 0 |
||
) | [protected] |
Crop the image to the given size and position.
int | null | $width | the width in pixels |
int | null | $height | the height in pixels |
int | $x | the x coordinate starting position from the left |
int | $y | the 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.
Reimplemented from P4Cms_Image_Driver_Abstract.
{ $geometry = $this->_getImagick()->getImageGeometry(); return $geometry['height']; }
P4Cms_Image_Driver_Imagick::_getImageWidth | ( | ) | [protected] |
Return 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.
{ if (!$this->_imagick) { $this->_imagick = new Imagick; } return $this->_imagick; }
static P4Cms_Image_Driver_Imagick::_getSupportedTypes | ( | ) | [static, protected] |
Return list of supported image types.
{
return Imagick::queryFormats();
}
P4Cms_Image_Driver_Imagick::_rotate | ( | $ | degrees | ) | [protected] |
Rotate the image.
float | $degrees | the 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.
int | $width | the width in pixels |
int | $height | the 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.
string | $type | optional - the image format (will return image data in the same format as input if not provided) |
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.
Implements P4Cms_Image_Driver_Interface.
{
return $this->_imagick !== null;
}
static P4Cms_Image_Driver_Imagick::isSupportedType | ( | $ | type | ) | [static] |
Check if given image type is supported.
string | $type | image type to check for |
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.
string | null | $data | optional - image data |
Implements P4Cms_Image_Driver_Interface.
{ if ($data) { $this->_getImagick()->readImageBlob($data); } else { $this->_imagick = null; } return $this; }
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] |
array( 'scale', 'sharpen', 'crop', 'rotate' )
Reimplemented from P4Cms_Image_Driver_Abstract.