Source for file IM.php
Documentation is available at IM.php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
* ImageMagick binaries 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
* @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: IM.php,v 1.25 2007/04/19 16:36:09 dufuz Exp $
* @link http://pear.php.net/package/Image_Transform
require_once 'Image/Transform.php';
require_once 'System.php';
* ImageMagick binaries implementation for Image_Transform package
* @package Image_Transform
* @subpackage Image_Transform_Driver_IM
* @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
* @link http://www.imagemagick.org/
* associative array commands to be executed
if (!defined('IMAGE_TRANSFORM_IM_PATH')) {
$path = dirname(System ::which ('convert'))
define('IMAGE_TRANSFORM_IM_PATH', $path);
if (System ::which (IMAGE_TRANSFORM_IM_PATH . 'convert' . ((OS_WINDOWS ) ? '.exe' : ''))) {
include 'Image/Transform/Driver/Imagick/ImageTypes.php';
$this->isError(PEAR ::raiseError ('Couldn\'t find "convert" binary',
* Initialize the state of the object
$this->command = array ();
* This method doesn't support remote files.
* @return mixed TRUE or a PEAR error object on error
return PEAR ::raiseError ('The image file ' . $image
if (PEAR ::isError ($result)) {
* Image_Transform_Driver_IM::_get_image_details()
* @param string $image the path and name of the image file
if (PEAR ::isError ($retval)) {
if (!System ::which (IMAGE_TRANSFORM_IM_PATH . 'identify' . ((OS_WINDOWS ) ? '.exe' : ''))) {
return PEAR ::raiseError ("Cannot fetch image or images details.", true );
* @param int $new_x New width
* @param int $new_y New height
* @param mixed $options Optional parameters
* @return true on success or PEAR Error object on error
function _resize($new_x, $new_y, $options = null )
if (isset ($this->command['resize'])) {
return PEAR ::raiseError ('You cannot scale or resize an image more than once without calling save() or display()', true );
$this->command['resize'] = '-geometry '
. ((int) $new_x) . 'x' . ((int) $new_y) . '!';
* @param int angle rotation angle
* @param array options no option allowed
* @return mixed TRUE or a PEAR error object on error
function rotate($angle, $options = null )
$this->command['rotate'] = '-rotate ' . (float) $angle;
* @author Ian Eure <ieure@websprockets.com>
* @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 mixed TRUE or a PEAR error object on error
function crop($width, $height, $x = 0 , $y = 0 ) {
// Do we want a safety check - i.e. if $width+$x > $this->img_x then we
// raise a warning? [and obviously same for $height+$y]
$this->command['crop'] = '-crop '
. ((int) $width) . 'x' . ((int) $height)
. '+' . ((int) $x) . '+' . ((int) $y);
// I think that setting img_x/y is wrong, but scaleByLength() & friends
// mess up the aspect after a crop otherwise.
* @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 mixed TRUE or a PEAR error object on error
if (true === $resize_first) {
// Set the key so that this will be the last item in the array
// Producing error: gs: not found gs: not found convert: Postscript delegate failed [No such file or directory].
* @param float $outputgamma
* @return mixed TRUE or a PEAR error object on error
function gamma($outputgamma = 1.0 ) {
if ($outputgamme != 1.0 ) {
$this->command['gamma'] = '-gamma ' . (float) $outputgamma;
* Convert the image to greyscale
* @return mixed TRUE or a PEAR error object on error
$this->command['type'] = '-type Grayscale';
* @return TRUE or PEAR Error object on error
// We can only apply "flop" once
if (isset ($this->command['flop'])) {
unset ($this->command['flop']);
$this->command['flop'] = '-flop';
* @return TRUE or PEAR Error object on error
// We can only apply "flip" once
if (isset ($this->command['flip'])) {
unset ($this->command['flip']);
$this->command['flip'] = '-flip';
* @param $filename string the name of the file to write to
* @param $quality quality image dpi, default=75
* @param $type string (JPEG, PNG...)
* @return mixed TRUE or a PEAR error object on error
function save($filename, $type = '', $quality = null )
$options['quality'] = $quality;
$quality = $this->_getOption('quality', $options, 75 );
. ' -quality ' . ((int) $quality) . ' '
return ($exit == 0 ) ? true : PEAR ::raiseError (implode('. ', $res),
* Display image without saving and lose changes
* This method adds the Content-type HTTP header
* @param string type (JPEG,PNG...);
* @return mixed TRUE or a PEAR error object on error
function display($type = '', $quality = null )
$options['quality'] = $quality;
$quality = $this->_getOption('quality', $options, 75 );
$this->_send_display_headers ($type);
implode(' ', $this->command) . " -quality $quality " .
$this->image . ' ' . $type . ":-");
$this->command = array ();
Documentation generated on Thu, 19 Apr 2007 13:30:11 -0400 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.
|