Source for file IM.php
Documentation is available at IM.php
/***********************************************************************
** Title.........: ImageMagick Driver
** Author........: Xiang Wei ZHUO <wei@zhuo.org>
** Filename......: IM.php
** Last changed..: 30 Aug 2003
** Notes.........: Orginal is from PEAR
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2002 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Peter Bowyer <peter@mapledesign.co.uk> |
// +----------------------------------------------------------------------+
// $Id: IM.php 26 2004-03-31 02:35:21Z Wei Zhuo $
// Image Transformation interface using command line ImageMagick
require_once "Transform.php";
* associative array commands to be executed
* @return mixed none or a PEAR error object on error
$this->uid = md5($_SERVER['REMOTE_ADDR']);
/*if (!file_exists($image)) {
return PEAR::raiseError('The image file ' . $image . ' does\'t exist', true);
$this->_get_image_details($image);
* @param int new_x new width
* @param int new_y new height
/*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 ${new_x}x${new_y}!";
* @param int $crop_x left column of the image
* @param int $crop_y top row of the image
* @param int $crop_width new cropped image width
* @param int $crop_height new cropped image height
function crop($crop_x, $crop_y, $crop_width, $crop_height)
$this->command['crop'] = "-crop {$crop_width}x{$crop_height}+{$crop_x}+{$crop_y}";
* Flip the image horizontally or vertically
* @param boolean $horizontal true if horizontal flip, vertical otherwise
function flip($horizontal)
* @param int angle rotation angle
* @param array options no option allowed
function rotate($angle, $options= null)
$angle = 360 - substr($angle, 1);
$this->command['rotate'] = "-rotate $angle";
* @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
'text' => 'This is Text',
'resize_first' => false // Carry out the scaling of the image before annotation?
if (true === $resize_first) {
// Set the key so that this will be the last item in the array
$this->command[$key] = "-font $font -fill $color -draw 'text $x,$y \"$text\"'";
// Producing error: gs: not found gs: not found convert: Postscript delegate failed [No such file or directory].
* @param float $outputgamma
function gamma($outputgamma= 1.0) {
$this->command['gamma'] = "-gamma $outputgamma";
* @param $filename string the name of the file to write to
* @param $quality quality image dpi, default=75
* @param $type string (JPG,PNG...)
function save($filename, $type= '', $quality = 85)
$type == '' ? $this->type : $type;
$cmd .= '"'. ($this->image) . '" "' . ($filename) . '" 2>&1';
//$cmd = str_replace('/', '\\', $cmd);
* Display image without saving and lose changes
* @param string type (JPG,PNG...);
function display($type = '', $quality = 75)
header('Content-type: image/' . $this->type);
header('Content-type: image/' . $type);
|