[ Index ]

PHP Cross Reference of Mambo 4.6.5

[ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/mambots/editors/mostlyce/jscripts/tiny_mce/imagemanager/Classes/ -> IM.php (source)

   1  <?php
   2  
   3  /***********************************************************************

   4  ** Title.........:  ImageMagick Driver

   5  ** Version.......:  1.0

   6  ** Author........:  Xiang Wei ZHUO <wei@zhuo.org>

   7  ** Filename......:  IM.php

   8  ** Last changed..:  30 Aug 2003 

   9  ** Notes.........:  Orginal is from PEAR

  10  **/
  11  
  12  // +----------------------------------------------------------------------+

  13  // | PHP Version 4                                                        |

  14  // +----------------------------------------------------------------------+

  15  // | Copyright (c) 1997-2002 The PHP Group                                |

  16  // +----------------------------------------------------------------------+

  17  // | This source file is subject to version 2.02 of the PHP license,      |

  18  // | that is bundled with this package in the file LICENSE, and is        |

  19  // | available at through the world-wide-web at                           |

  20  // | http://www.php.net/license/2_02.txt.                                 |

  21  // | If you did not receive a copy of the PHP license and are unable to   |

  22  // | obtain it through the world-wide-web, please send a note to          |

  23  // | license@php.net so we can mail you a copy immediately.               |

  24  // +----------------------------------------------------------------------+

  25  // | Authors: Peter Bowyer <peter@mapledesign.co.uk>                      |

  26  // +----------------------------------------------------------------------+

  27  //

  28  // $Id$

  29  //

  30  // Image Transformation interface using command line ImageMagick

  31  //

  32  
  33  require_once  "Transform.php";
  34  
  35  Class Image_Transform_Driver_IM extends Image_Transform
  36  {
  37      /**

  38       * associative array commands to be executed

  39       * @var array

  40       */
  41      var $command = array();
  42  
  43      /**

  44       *

  45       *

  46       */
  47      function Image_Transform_Driver_IM()
  48      {
  49          return true;
  50      } // End Image_IM

  51  
  52      /**

  53       * Load image

  54       *

  55       * @param string filename

  56       *

  57       * @return mixed none or a PEAR error object on error

  58       * @see PEAR::isError()

  59       */
  60      function load($image)
  61      {
  62  
  63          $this->uid = md5($_SERVER['REMOTE_ADDR']);
  64          /*if (!file_exists($image)) {

  65              return PEAR::raiseError('The image file ' . $image . ' does\'t exist', true);

  66          }*/
  67          $this->image = $image;
  68          $this->_get_image_details($image);
  69      } // End load

  70  
  71      /**

  72       * Resize Action

  73       *

  74       * @param int   new_x   new width

  75       * @param int   new_y   new height

  76       *

  77       * @return none

  78       * @see PEAR::isError()

  79       */
  80      function _resize($new_x, $new_y)
  81      {
  82          /*if (isset($this->command['resize'])) {

  83              return PEAR::raiseError("You cannot scale or resize an image more than once without calling save or display", true);

  84          }*/
  85          $this->command['resize'] = "-geometry $new_x}x$new_y}!";
  86  
  87          $this->new_x = $new_x;
  88          $this->new_y = $new_y;
  89      } // End resize

  90  
  91      /**

  92       * Crop the image

  93       *

  94       * @param int $crop_x left column of the image

  95       * @param int $crop_y top row of the image

  96       * @param int $crop_width new cropped image width

  97       * @param int $crop_height new cropped image height

  98       */
  99      function crop($crop_x, $crop_y, $crop_width, $crop_height) 
 100      {
 101          $this->command['crop'] = "-crop {$crop_width}x{$crop_height}+{$crop_x}+{$crop_y}";
 102      }
 103  
 104      /**

 105       * Flip the image horizontally or vertically

 106       *

 107       * @param boolean $horizontal true if horizontal flip, vertical otherwise

 108       */
 109      function flip($horizontal) 
 110      {
 111          if($horizontal)
 112              $this->command['flop'] = "-flop";
 113          else
 114              $this->command['flip'] = "-flip";
 115      }
 116      /**

 117       * rotate

 118       *

 119       * @param   int     angle   rotation angle

 120       * @param   array   options no option allowed

 121       *

 122       */
 123      function rotate($angle, $options=null)
 124      {
 125          if ('-' == $angle{0}) {
 126              $angle = 360 - substr($angle, 1);
 127          }
 128           $this->command['rotate'] = "-rotate $angle";
 129      } // End rotate

 130  
 131      /**

 132       * addText

 133       *

 134       * @param   array   options     Array contains options

 135       *                              array(

 136       *                                  'text'  The string to draw

 137       *                                  'x'     Horizontal position

 138       *                                  'y'     Vertical Position

 139       *                                  'Color' Font color

 140       *                                  'font'  Font to be used

 141       *                                  'size'  Size of the fonts in pixel

 142       *                                  'resize_first'  Tell if the image has to be resized

 143       *                                                  before drawing the text

 144       *                              )

 145       *

 146       * @return none

 147       * @see PEAR::isError()

 148       */
 149      function addText($params)
 150      {
 151          $default_params = array(
 152                                  'text' => 'This is Text',
 153                                  'x' => 10,
 154                                  'y' => 20,
 155                                  'color' => 'red',
 156                                  'font' => 'Arial.ttf',
 157                                  'resize_first' => false // Carry out the scaling of the image before annotation?
 158                                  );
 159           $params = array_merge($default_params, $params);
 160           extract($params);
 161           if (true === $resize_first) {
 162               // Set the key so that this will be the last item in the array

 163              $key = 'ztext';
 164           } else {
 165              $key = 'text';
 166           }
 167           $this->command[$key] = "-font $font -fill $color -draw 'text $x,$y \"$text\"'";
 168           // Producing error: gs: not found gs: not found convert: Postscript delegate failed [No such file or directory].

 169      } // End addText

 170  
 171      /**

 172       * Adjust the image gamma

 173       *

 174       * @param float $outputgamma

 175       *

 176       * @return none

 177       */
 178      function gamma($outputgamma=1.0) {
 179          $this->command['gamma'] = "-gamma $outputgamma";
 180      }
 181  
 182      /**

 183       * Save the image file

 184       *

 185       * @param $filename string  the name of the file to write to

 186       * @param $quality  quality image dpi, default=75

 187       * @param $type     string  (JPG,PNG...)

 188       *

 189       * @return none

 190       */
 191      function save($filename, $type='', $quality = 85)
 192      {
 193          $type == '' ? $this->type : $type;
 194          $cmd = '' . IMAGE_TRANSFORM_LIB_PATH . 'convert ';
 195          $cmd .= implode(' ', $this->command) . " -quality $quality ";
 196          $cmd .= '"'.($this->image) . '" "' . ($filename) . '" 2>&1';
 197          
 198          //$cmd = str_replace('/', '\\', $cmd);

 199          //echo($cmd.'<br>');

 200          exec($cmd,$retval);
 201      } // End save

 202  
 203      /**

 204       * Display image without saving and lose changes

 205       *

 206       * @param string type (JPG,PNG...);

 207       * @param int quality 75

 208       *

 209       * @return none

 210       */
 211      function display($type = '', $quality = 75)
 212      {
 213          if ($type == '') {
 214              header('Content-type: image/' . $this->type);
 215              passthru(IMAGE_TRANSFORM_LIB_PATH . 'convert ' . implode(' ', $this->command) . " -quality $quality "  . escapeshellarg($this->image) . ' ' . strtoupper($this->type) . ":-");
 216          } else {
 217              header('Content-type: image/' . $type);
 218              passthru(IMAGE_TRANSFORM_LIB_PATH . 'convert ' . implode(' ', $this->command) . " -quality $quality "  . escapeshellarg($this->image) . ' ' . strtoupper($type) . ":-");
 219          }
 220      }
 221  
 222  
 223      /**

 224       * Destroy image handle

 225       *

 226       * @return none

 227       */
 228      function free()
 229      {
 230          return true;
 231      }
 232  
 233  } // End class ImageIM

 234  ?>