Image_Transform
[ class tree: Image_Transform ] [ index: Image_Transform ] [ all elements ]

Source for file Imagick.php

Documentation is available at Imagick.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  4.  
  5. /**
  6.  * Image Transformation interface using old ImageMagick extension
  7.  *
  8.  * PHP versions 4 and 5
  9.  *
  10.  * LICENSE: This source file is subject to version 3.0 of the PHP license
  11.  * that is available through the world-wide-web at the following URI:
  12.  * http://www.php.net/license/3_0.txt.  If you did not receive a copy of
  13.  * the PHP License and are unable to obtain it through the web, please
  14.  * send a note to license@php.net so we can mail you a copy immediately.
  15.  *
  16.  * @category   Image
  17.  * @package    Image_Transform
  18.  * @author     Peter Bowyer <peter@mapledesign.co.uk>
  19.  * @copyright  2002-2005 The PHP Group
  20.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  21.  * @version    CVS: $Id: Imagick.php,v 1.9 2007/04/19 16:36:09 dufuz Exp $
  22.  * @deprecated
  23.  * @link       http://pear.php.net/package/Image_Transform
  24.  */
  25.  
  26. /**
  27.  * Include of base class
  28.  */
  29. require_once 'Image/Transform.php';
  30.  
  31.  
  32. /**
  33.  * Image Transformation interface using old ImageMagick extension
  34.  *
  35.  * DEPRECATED: current CVS/release imagick extension should use
  36.  * the Imagick2 driver
  37.  *
  38.  * @deprecated
  39.  */
  40. {
  41.     /**
  42.      * Handler of the imagick image ressource
  43.      * @var array 
  44.      */
  45.     var $imageHandle;
  46.  
  47.     /**
  48.      * Handler of the image ressource before
  49.      * the last transformation
  50.      * @var array 
  51.      */
  52.     var $oldImage;
  53.  
  54.     /**
  55.      *
  56.      *
  57.      */
  58.     function Image_Transform_Driver_Imagick()
  59.     {
  60.         if (!PEAR::loadExtension('imagick')) {
  61.             return PEAR::raiseError('The imagick extension can not be found.'true);
  62.         }
  63.         include 'Image/Transform/Driver/Imagick/ImageTypes.php';
  64.         return true;
  65.     // End Image_IM
  66.  
  67.     
  68.     /**
  69.      * Load image
  70.      *
  71.      * @param string filename
  72.      *
  73.      * @return mixed none or a PEAR error object on error
  74.      * @see PEAR::isError()
  75.      */
  76.     function load($image)
  77.     {
  78.         $this->imageHandle = imagick_create();
  79.         if !is_resource$this->imageHandle ) ) {
  80.             return PEAR::raiseError('Cannot initialize imagick image.'true);
  81.         }
  82.  
  83.         if !imagick_read($this->imageHandle$image) ){
  84.             return PEAR::raiseError('The image file ' $image ' does\'t exist'true);
  85.         }
  86.         $this->image = $image;
  87.         $result $this->_get_image_details($image);
  88.         if (PEAR::isError($result)) {
  89.             return $result;
  90.         }
  91.     // End load
  92.  
  93.     
  94.     /**
  95.      * Resize Action
  96.      *
  97.      * @param int   new_x   new width
  98.      * @param int   new_y   new width
  99.      * @param mixed $options Optional parameters
  100.      *
  101.      * @return none 
  102.      * @see PEAR::isError()
  103.      */
  104.     function _resize($new_x$new_y$options = null)
  105.     {
  106.         if ($img2 = imagick_copy_resize($this->imageHandle$new_x$new_yIMAGICK_FILTER_CUBIC1)){
  107.             $this->oldImage = $this->imageHandle;
  108.             $this->imageHandle =$img2;
  109.             $this->new_x = $new_x;
  110.             $this->new_y = $new_y;
  111.         else {
  112.             return PEAR::raiseError("Cannot create a new imagick imagick image for the resize."true);
  113.         }
  114.     // End resize
  115.  
  116.     
  117.     /**
  118.      * rotate
  119.      * Note: color mask are currently not supported
  120.      *
  121.      * @param   int     Rotation angle in degree
  122.      * @param   array   No option are actually allowed
  123.      *
  124.      * @return none 
  125.      * @see PEAR::isError()
  126.      */
  127.     function rotate($angle,$options=null)
  128.     {
  129.         if ($img2 = imagick_copy_rotate ($this->imageHandle$angle)){
  130.             $this->oldImage     = $this->imageHandle;
  131.             $this->imageHandle  = $img2;
  132.             $this->new_x = imagick_get_attribute($img2,'width');
  133.             $this->new_y = imagick_get_attribute($img2,'height');
  134.         else {
  135.             return PEAR::raiseError("Cannot create a new imagick imagick image for the resize."true);
  136.         }
  137.     // End rotate
  138.  
  139.     
  140.     /**
  141.      * addText
  142.      *
  143.      * @param   array   options     Array contains options
  144.      *                               array(
  145.      *                                   'text'  The string to draw
  146.      *                                   'x'     Horizontal position
  147.      *                                   'y'     Vertical Position
  148.      *                                   'Color' Font color
  149.      *                                   'font'  Font to be used
  150.      *                                   'size'  Size of the fonts in pixel
  151.      *                                   'resize_first'  Tell if the image has to be resized
  152.      *                                                   before drawing the text
  153.      *                               )
  154.      *
  155.      * @return none 
  156.      * @see PEAR::isError()
  157.      */
  158.     function addText($params)
  159.     {
  160.         $default_params = array(
  161.                                 'text'          => 'This is a Text',
  162.                                 'x'             => 10,
  163.                                 'y'             => 20,
  164.                                 'size'          => 12,
  165.                                 'color'         => 'red',
  166.                                 'font'          => 'Arial.ttf',
  167.                                 'resize_first'  => false // Carry out the scaling of the image before annotation?
  168.                                 );
  169.         $params array_merge($default_params$params);
  170.         extract($params);
  171.  
  172.         $color is_array($color)?$this->colorarray2colorhex($color):strtolower($color);
  173.  
  174.         imagick_annotate($this->imageHandle,array(
  175.                     "primitive"     => "text $x,$y ".$text,
  176.                     "pointsize"     => $size,
  177.                     "antialias"     => 0,
  178.                     "fill"          => $color,
  179.                     "font"          => $font,
  180.                     ));
  181.     // End addText
  182.  
  183.     
  184.     /**
  185.      * Save the image file
  186.      *
  187.      * @param $filename string the name of the file to write to
  188.      *
  189.      * @return none 
  190.      */
  191.     function save($filename$type=''$quality = 75)
  192.     {
  193.         if (function_exists('imagick_setcompressionquality')) {
  194.             imagick_setcompressionquality($this->imageHandle$quality);
  195.         }
  196.         if ($type != ''{
  197.             $type strtoupper($type);
  198.             imagick_write($this->imageHandle$filename$type);
  199.         else {
  200.             imagick_write($this->imageHandle$filename);
  201.         }
  202.         imagick_free($handle);
  203.     // End save
  204.  
  205.     
  206.     /**
  207.      * Display image without saving and lose changes
  208.      *
  209.      * @param string type (JPG,PNG...);
  210.      * @param int quality 75
  211.      *
  212.      * @return none 
  213.      */
  214.     function display($type ''$quality = 75)
  215.     {
  216.         if ($type == ''{
  217.             header('Content-type: image/' $this->type);
  218.             if (!imagick_dump($this->imageHandle));
  219.         else {
  220.             header('Content-type: image/' $type);
  221.             if (!imagick_dump($this->imageHandle$this->type));
  222.         }
  223.         $this->free();
  224.     }
  225.  
  226.  
  227.     /**
  228.      * Destroy image handle
  229.      *
  230.      * @return none 
  231.      */
  232.     function free()
  233.     {
  234.         if (is_resource($this->imageHandle)){
  235.             imagick_free($this->imageHandle);
  236.         }
  237.         if (is_resource($this->oldImage)){
  238.             imagick_free($this->oldImage);
  239.         }
  240.         return true;
  241.     }
  242.  

Documentation generated on Thu, 19 Apr 2007 13:30:13 -0400 by phpDocumentor 1.3.0. PEAR Logo Copyright © PHP Group 2004.