Source for file Imagick2.php
Documentation is available at Imagick2.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
* imagick PECL extension implementation for Image_Transform package
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
* @package Image_Transform
* @subpackage Image_Transform_Driver_Imagick2
* @author Alan Knowles <alan@akbkhome.com>
* @author Peter Bowyer <peter@mapledesign.co.uk>
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
* @copyright 2002-2005 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id: Imagick2.php,v 1.10 2007/04/19 16:36:09 dufuz Exp $
* @link http://pear.php.net/package/Image_Transform
require_once 'Image/Transform.php';
* imagick PECL extension implementation for Image_Transform package
* EXPERIMENTAL - please report bugs
* Use the latest cvs version of imagick PECL
* @package Image_Transform
* @subpackage Image_Transform_Driver_Imagick2
* @author Alan Knowles <alan@akbkhome.com>
* @author Peter Bowyer <peter@mapledesign.co.uk>
* @author Philippe Jausions <Philippe.Jausions@11abacus.com>
* @copyright 2002-2005 The PHP Group
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: @package_version@
* @link http://pear.php.net/package/Image_Transform
* Handler of the imagick image ressource
} // End Image_Transform_Driver_Imagick2
* @see http://www.imagemagick.org/www/formats.html
if (PEAR ::loadExtension ('imagick')) {
include 'Image/Transform/Driver/Imagick/ImageTypes.php';
$this->isError(PEAR ::raiseError ('Couldn\'t find the imagick extension.',
* @param string $image filename
* @return bool|PEAR_ErrorTRUE or a PEAR_Error object on error
if (!($this->imageHandle = imagick_readimage ($image))) {
if (PEAR ::isError ($result)) {
* @param int $new_x New width
* @param int $new_y New height
* @param mixed $options Optional parameters
* @return bool|PEAR_ErrorTRUE or PEAR_Error object on error
function _resize($new_x, $new_y, $options = null )
if (!imagick_resize ($this->imageHandle, $new_x, $new_y, IMAGICK_FILTER_UNKNOWN , 1 )) {
return $this->raiseError('Couldn\'t resize image.',
* Rotates the current image
* Note: color mask are currently not supported
* @param int Rotation angle in degree
* @param array No options are currently supported
* @return bool|PEAR_ErrorTRUE or a PEAR_Error object on error
function rotate($angle, $options = null )
if (($angle % 360 ) == 0 ) {
return $this->raiseError('Cannot create a new imagick image for the rotation.',
* @param array options Array contains options
* 'text' The string to draw
* 'x' Horizontal position
* 'size' Size of the fonts in pixel
* 'resize_first' Tell if the image has to be resized
* before drawing the text
* @return bool|PEAR_ErrorTRUE or a PEAR_Error object on error
static $default_params = array (
'text' => 'This is a Text',
'resize_first' => false // Carry out the scaling of the image before annotation?
$params = array_merge ($default_params, $params);
'setfillcolor' => 'color',
imagick_begindraw ($this->imageHandle ) ;
foreach ($cmds as $cmd => $v) {
return $this->raiseError(" Problem with adding Text::{$v} = {$parms[$v]}" ,
if (!imagick_drawannotation ($this->imageHandle, $params['x'], $params['y'], $params['text'])) {
return $this->raiseError('Problem with adding Text',
* Saves the image to a file
* @param $filename string the name of the file to write to
* @return bool|PEAR_ErrorTRUE or a PEAR_Error object on error
function save($filename, $type = '', $quality = null )
$options = (is_array($quality)) ? $quality : array ();
$options['quality'] = $quality;
$quality = $this->_getOption('quality', $options, 75 );
imagick_setcompressionquality ($this->imageHandle, $quality);
return $this->raiseError('Couldn\'t save image to file (conversion failed).',
return $this->raiseError('Couldn\'t save image to file.',
* Displays image without saving and lose changes
* This method adds the Content-type HTTP header
* @param string type (JPG,PNG...);
* @return bool|PEAR_ErrorTRUE or a PEAR_Error object on error
function display($type = '', $quality = null )
$options = (is_array($quality)) ? $quality : array ();
$options['quality'] = $quality;
$quality = $this->_getOption('quality', $options, 75 );
imagick_setcompressionquality ($this->imageHandle, $quality);
if ($type && strcasecomp ($type, $this->type)
return $this->raiseError('Couldn\'t save image to file (conversion failed).',
if (!($image = imagick_image2blob ($this->imageHandle))) {
return $this->raiseError('Couldn\'t display image.',
* Adjusts the image gamma
* @param float $outputgamma
* @return bool|PEAR_ErrorTRUE or a PEAR_Error object on error
function gamma($outputgamma = 1.0 ) {
if ($outputgamma != 1.0 ) {
* @param int width Cropped image width
* @param int height Cropped image height
* @param int x X-coordinate to crop at
* @param int y Y-coordinate to crop at
* @return bool|PEAR_ErrorTRUE or a PEAR_Error object on error
function crop($width, $height, $x = 0 , $y = 0 )
if (!$this->intersects($width, $height, $x, $y)) {
if (!imagick_crop ($this->imageHandle, $x, $y, $width, $height)) {
// I think that setting img_x/y is wrong, but scaleByLength() & friends
// mess up the aspect after a crop otherwise.
* @return bool|PEAR_ErrorTRUE or a PEAR_Error object on error
return $this->raiseError('Couldn\'t mirror the image.',
* @return bool|PEAR_ErrorTRUE or a PEAR_Error object on error
return $this->raiseError('Couldn\'t flip the image.',
* RaiseError Method - shows imagick Raw errors.
* @param string $message message = prefixed message..
* @param int $code error code
* @return PEAR error object
return PEAR ::raiseError ($message, $code);
Documentation generated on Thu, 19 Apr 2007 13:30:15 -0400 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.
|