Start splitting up Horde_Image into more atomic objects
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 2 Aug 2009 15:47:49 +0000 (11:47 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sun, 2 Aug 2009 15:47:49 +0000 (11:47 -0400)
framework/Image/lib/Horde/Image.php
framework/Image/lib/Horde/Image/Base.php [new file with mode: 0644]
framework/Image/lib/Horde/Image/Gd.php
framework/Image/lib/Horde/Image/Im.php
framework/Image/lib/Horde/Image/Imagick.php
framework/Image/lib/Horde/Image/Png.php
framework/Image/lib/Horde/Image/Svg.php
framework/Image/lib/Horde/Image/Swf.php
framework/Image/package.xml

index dc4d1cf..cac0f33 100644 (file)
@@ -1,7 +1,8 @@
 <?php
 /**
- * This class defines the Horde_Image:: API, and also provides some
- * utility functions, such as generating highlights of a color.
+ * This class provides some utility functions, such as generating highlights
+ * of a color as well as a factory method responsible for creating a concerete
+ * Horde_Image driver.
  *
  * Copyright 2002-2009 The Horde Project (http://www.horde.org/)
  *
  * @author  Michael J. Rubinsky <mrubinsk@horde.org>
  *
  * @package Horde_Image
- *
- * @TODO: - Can we depend on the Horde_Util:: class or some other solution needed?
- *        - Exceptions
  */
 class Horde_Image
 {
-    /**
-     * Background color.
-     *
-     * @var string
-     */
-    protected $_background = 'white';
-
-    /**
-     * Observers.
-     *
-     * @var array
-     */
-    protected $_observers = array();
-
-    /**
-     * Capabilites of this driver.
-     *
-     * @var array
-     */
-    protected $_capabilities = array();
-
-    /**
-     * The current image data.
-     *
-     * @var string
-     */
-    protected $_data = '';
-
-    /**
-     * The current image id.
-     *
-     * @TODO: Do we *really* need an image id...and if so, we can make the
-     *        parameter optional in the methods that take one?
-     *
-     * @var string
-     */
-    protected $_id = '';
-
-    /**
-     * Logger
-     */
-    protected $_logger;
-
-    /**
-     * The current width of the image data.
-     *
-     * @var integer
-     */
-    protected $_width = 0;
-
-    /**
-     * The current height of the image data.
-     *
-     * @var integer
-     */
-    protected $_height = 0;
-
-    /**
-     * A directory for temporary files.
-     *
-     * @var string
-     */
-    protected $_tmpdir;
-
-    /**
-     * Array containing available Effects
-     *
-     * @var array
-     */
-    protected $_loadedEffects = array();
-
-    /**
-     * What kind of images should ImageMagick generate? Defaults to 'png'.
-     *
-     * @var string
-     */
-    protected $_type = 'png';
-
-    /**
-     * Constructor.
-     *
-     * @param string $rgb  The base color for generated pixels/images.
-     */
-    protected function __construct($params, $context = array())
-    {
-        //@TODO: This is a temporary BC hack until I update all new Horde_Image calls
-        if (empty($context['tmpdir'])) {
-            throw new InvalidArgumentException('A path to a temporary directory is required.');
-        }
-        $this->_tmpdir = $context['tmpdir'];
-        if (isset($params['width'])) {
-            $this->_width = $params['width'];
-        }
-        if (isset($params['height'])) {
-            $this->_height = $params['height'];
-        }
-        if (!empty($params['type'])) {
-            $this->_type = $params['type'];
-        }
-
-        if (!empty($context['logger'])) {
-            $this->_logger = $context['logger'];
-        }
-
-        $this->_background = isset($params['background']) ? $params['background'] : 'white';
-    }
-
-    /**
-     * Getter for the capabilities array
-     *
-     * @return array
-     */
-    public function getCapabilities()
-    {
-        return $this->_capabilities;
-    }
-
-    /**
-     * Check the existence of a particular capability.
-     *
-     * @param string $capability  The capability to check for.
-     *
-     * @return boolean
-     */
-    public function hasCapability($capability)
-    {
-        return in_array($capability, $this->_capabilities);
-    }
-
-    /**
-     * Generate image headers.
-     */
-    public function headers()
-    {
-        header('Content-type: ' . $this->getContentType());
-    }
-
-    /**
-     * Return the content type for this image.
-     *
-     * @return string  The content type for this image.
-     */
-    public function getContentType()
-    {
-        return 'image/' . $this->_type;
-    }
-
-    /**
-     * Getter for the simplified image type.
-     *
-     * @return string  The type of image (png, jpg, etc...)
-     */
-    public function getType()
-    {
-        return $this->_type;
-    }
-
+    static protected $_loadedEffects = array();
     /**
      * Calculate a lighter (or darker) version of a color.
      *
@@ -296,186 +138,6 @@ class Horde_Image
     }
 
     /**
-     * Draw a shaped point at the specified (x,y) point. Useful for
-     * scatter diagrams, debug points, etc. Draws squares, circles,
-     * diamonds, and triangles.
-     *
-     * @param integer $x     The x coordinate of the point to brush.
-     * @param integer $y     The y coordinate of the point to brush.
-     * @param string $color  The color to brush the point with.
-     * @param string $shape  What brush to use? Defaults to a square.
-     */
-    public function brush($x, $y, $color = 'black', $shape = 'square')
-    {
-        switch ($shape) {
-        case 'triangle':
-            $verts[0] = array('x' => $x + 3, 'y' => $y + 3);
-            $verts[1] = array('x' => $x, 'y' => $y - 3);
-            $verts[2] = array('x' => $x - 3, 'y' => $y + 3);
-            $this->polygon($verts, $color, $color);
-            break;
-
-        case 'circle':
-            $this->circle($x, $y, 3, $color, $color);
-            break;
-
-        case 'diamond':
-            $verts[0] = array('x' => $x - 3, 'y' => $y);
-            $verts[1] = array('x' => $x, 'y' => $y + 3);
-            $verts[2] = array('x' => $x + 3, 'y' => $y);
-            $verts[3] = array('x' => $x, 'y' => $y - 3);
-            $this->polygon($verts, $color, $color);
-            break;
-
-        case 'square':
-        default:
-            $this->rectangle($x - 2, $y - 2, 4, 4, $color, $color);
-            break;
-        }
-    }
-
-    /**
-     * Add an observer to this image. The observer will be notified
-     * when the image's changes.
-     */
-    public function addObserver($method, $object)
-    {
-        $this->_observers[] = array($method, $object);
-    }
-
-    /**
-     * Let observers know that something happened worth acting on.
-     */
-    public function notifyObservers()
-    {
-        for ($i = 0; $i < count($this->_observers); ++$i) {
-            $obj = $this->_observers[$i][1];
-            $method = $this->_observers[$i][0];
-            $obj->$method($this);
-        }
-    }
-
-    /**
-     * Reset the image data to defaults.
-     */
-    public function reset()
-    {
-        $this->_data = '';
-        $this->_id = '';
-        $this->_width = null;
-        $this->_height = null;
-        $this->_background = 'white';
-        $this->_type = 'png';
-    }
-
-    /**
-     * Get the height and width of the current image data.
-     *
-     * @return array  An hash with 'width' containing the width,
-     *                'height' containing the height of the image.
-     */
-    public function getDimensions()
-    {
-        // Check if we know it already
-        if ($this->_width == 0 && $this->_height == 0) {
-            $tmp = $this->toFile();
-            $details = @getimagesize($tmp);
-            list($this->_width, $this->_height) = $details;
-            unlink($tmp);
-        }
-
-        return array('width' => $this->_width,
-                     'height' => $this->_height);
-    }
-
-    /**
-     * Load the image data from a string.
-     *
-     * @param string $id          An arbitrary id for the image.
-     * @param string $image_data  The data to use for the image.
-     */
-    public function loadString($id, $image_data)
-    {
-        if ($id != $this->_id) {
-            $this->reset();
-            $this->_data = $image_data;
-            $this->_id = $id;
-        }
-    }
-
-    /**
-     * Load the image data from a file.
-     *
-     * @param string $filename  The full path and filename to the file to load
-     *                          the image data from. The filename will also be
-     *                          used for the image id.
-     *
-     * @return mixed  True if successful or already loaded, PEAR Error if file
-     *                does not exist or could not be loaded.
-     */
-    public function loadFile($filename)
-    {
-        if ($filename != $this->_id) {
-            $this->reset();
-            if (!file_exists($filename)) {
-                return PEAR::raiseError('The image file ' . $filename . ' does not exist.');
-            }
-            if ($this->_data = file_get_contents($filename)) {
-                $this->_id = $filename;
-            } else {
-                return PEAR::raiseError('Could not load the image file ' . $filename);
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * Ouputs image data to file.  If $data is false, outputs current
-     * image data after performing any pending operations on the data.
-     * If $data contains raw image data, outputs that data to file without
-     * regard for $this->_data
-     *
-     * @param mixed  String of binary image data | false
-     *
-     * @return string  Path to temporary file.
-     */
-    public function toFile($data = false)
-    {
-        $tmp = Horde_Util::getTempFile('img', false, $this->_tmpdir);
-        $fp = @fopen($tmp, 'wb');
-        fwrite($fp, $data ? $data : $this->raw());
-        fclose($fp);
-        return $tmp;
-    }
-
-    /**
-     * Display the current image.
-     */
-    public function display()
-    {
-        $this->headers();
-        echo $this->raw();
-    }
-
-    /**
-     * Returns the raw data for this image.
-     *
-     * @param boolean $convert  If true, the image data will be returned in the
-     *                          target format, independently from any image
-     *                          operations.
-     *
-     * @return string  The raw image data.
-     */
-    public function raw($convert = false)
-    {
-        return $this->_data;
-    }
-
-    // @TODO:  I don't see why these need to be private/protected...
-    //         probably can just make them static. Right now, I think
-    //         only _arcPoints is used (in gd.php)
-    /**
      * Get an x,y pair on circle, assuming center is 0,0.
      *
      * @access private
@@ -485,7 +147,7 @@ class Horde_Image
      *
      * @return array  (x coordinate, y coordinate) of the point.
      */
-    static protected function _circlePoint($degrees, $diameter)
+    static public function circlePoint($degrees, $diameter)
     {
         // Avoid problems with doubles.
         $degrees += 0.0001;
@@ -506,7 +168,7 @@ class Horde_Image
      *
      * @return array  The start point, end point, and anchor point.
      */
-    static protected function _arcPoints($r, $start, $end)
+    static public function arcPoints($r, $start, $end)
     {
         // Start point.
         $pts['x1'] = $r * cos(deg2rad($start));
@@ -526,70 +188,6 @@ class Horde_Image
     }
 
     /**
-     * Attempts to apply requested effect to this image.  If the
-     * effect cannot be found a PEAR_Error is returned.
-     *
-     * @param string $type    The type of effect to apply.
-     * @param array $params   Any parameters for the effect.
-     *
-     * @return mixed  true on success | PEAR_Error on failure.
-     */
-    public function addEffect($type, $params)
-    {
-        $class = str_replace('Horde_Image_', '', get_class($this));
-        $effect = Horde_Image_Effect::factory($type, $class, $params);
-        if (is_a($effect, 'PEAR_Error')) {
-            return $effect;
-        }
-        $effect->setImageObject($this);
-        return $effect->apply();
-    }
-
-    /**
-     * Load a list of available effects for this driver.
-     */
-    public function getLoadedEffects()
-    {
-        if (empty($this->_loadedEffects)) {
-            $class = str_replace('Horde_Image_', '', get_class($this));
-
-            // First, load the driver-agnostic Effects.
-            $path = dirname(__FILE__) . '/Image/Effect/';
-            if (is_dir($path)) {
-                if ($handle = opendir($path)) {
-                    while (($file = readdir($handle)) !== false) {
-                        if (substr($file, -4, 4) == '.php') {
-                            $this->_loadedEffects[] = substr($file, 0, strlen($file) - 4);
-                        }
-                    }
-                }
-            }
-
-            // Driver specific effects.
-            $path = $path . $class;
-            if (is_dir($path)) {
-                if ($handle = opendir($path)) {
-                    while (($file = readdir($handle)) !== false) {
-                        if (substr($file, -4, 4) == '.php') {
-                            $this->_loadedEffects[] = substr($file, 0, strlen($file) - 4);
-                        }
-                    }
-                }
-            }
-        }
-
-        return $this->_loadedEffects;
-    }
-
-    /**
-     * Apply any effects in the effect queue.
-     */
-    public function applyEffects()
-    {
-        $this->raw();
-    }
-
-    /**
      * Attempts to return a concrete Horde_Image instance based on $driver.
      *
      * @param mixed $driver  The type of concrete Horde_Image subclass to
@@ -634,37 +232,6 @@ class Horde_Image
         return $image;
     }
 
-    public function getTmpDir()
-    {
-        return $this->_tmpdir;
-    }
-
-    /**
-     * Utility function to zero out cached geometry information. Shouldn't
-     * really be called from client code, but is needed since Effects may need
-     * to clear these.
-     *
-     */
-    public function clearGeometry()
-    {
-        $this->_height = 0;
-        $this->_width = 0;
-    }
-
-    protected function _logDebug($message)
-    {
-        if (!empty($this->_logger)) {
-            $this->_logger->debug($message);
-        }
-    }
-
-    protected function _logErr($message)
-    {
-        if (!empty($this->_logger)) {
-            $this->_logger->err($message);
-        }
-    }
-
     /**
      * Return point size for font
      */
diff --git a/framework/Image/lib/Horde/Image/Base.php b/framework/Image/lib/Horde/Image/Base.php
new file mode 100644 (file)
index 0000000..fc31e55
--- /dev/null
@@ -0,0 +1,450 @@
+<?php
+/**
+ * This class defines the Horde_Image:: API, and also provides some
+ * utility functions, such as generating highlights of a color.
+ *
+ * Copyright 2002-2009 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Chuck Hagenbuch <chuck@horde.org>
+ * @author  Michael J. Rubinsky <mrubinsk@horde.org>
+ *
+ * @package Horde_Image
+ *
+ * @TODO: - Can we depend on the Horde_Util:: class or some other solution needed?
+ *        - Exceptions
+ */
+class Horde_Image_Base
+{
+    /**
+     * Background color.
+     *
+     * @var string
+     */
+    protected $_background = 'white';
+
+    /**
+     * Observers.
+     *
+     * @var array
+     */
+    protected $_observers = array();
+
+    /**
+     * Capabilites of this driver.
+     *
+     * @var array
+     */
+    protected $_capabilities = array();
+
+    /**
+     * The current image data.
+     *
+     * @var string
+     */
+    protected $_data = '';
+
+    /**
+     * The current image id.
+     *
+     * @TODO: Do we *really* need an image id...and if so, we can make the
+     *        parameter optional in the methods that take one?
+     *
+     * @var string
+     */
+    protected $_id = '';
+
+    /**
+     * Logger
+     */
+    protected $_logger;
+
+    /**
+     * The current width of the image data.
+     *
+     * @var integer
+     */
+    protected $_width = 0;
+
+    /**
+     * The current height of the image data.
+     *
+     * @var integer
+     */
+    protected $_height = 0;
+
+    /**
+     * A directory for temporary files.
+     *
+     * @var string
+     */
+    protected $_tmpdir;
+
+    /**
+     * Array containing available Effects
+     *
+     * @var array
+     */
+    protected $_loadedEffects = array();
+
+    /**
+     * What kind of images should ImageMagick generate? Defaults to 'png'.
+     *
+     * @var string
+     */
+    protected $_type = 'png';
+
+    /**
+     * Constructor.
+     *
+     * @param string $rgb  The base color for generated pixels/images.
+     */
+    protected function __construct($params, $context = array())
+    {
+        //@TODO: This is a temporary BC hack until I update all new Horde_Image calls
+        if (empty($context['tmpdir'])) {
+            throw new InvalidArgumentException('A path to a temporary directory is required.');
+        }
+        $this->_tmpdir = $context['tmpdir'];
+        if (isset($params['width'])) {
+            $this->_width = $params['width'];
+        }
+        if (isset($params['height'])) {
+            $this->_height = $params['height'];
+        }
+        if (!empty($params['type'])) {
+            $this->_type = $params['type'];
+        }
+
+        if (!empty($context['logger'])) {
+            $this->_logger = $context['logger'];
+        }
+
+        $this->_background = isset($params['background']) ? $params['background'] : 'white';
+    }
+
+    /**
+     * Getter for the capabilities array
+     *
+     * @return array
+     */
+    public function getCapabilities()
+    {
+        return $this->_capabilities;
+    }
+
+    /**
+     * Check the existence of a particular capability.
+     *
+     * @param string $capability  The capability to check for.
+     *
+     * @return boolean
+     */
+    public function hasCapability($capability)
+    {
+        return in_array($capability, $this->_capabilities);
+    }
+
+    /**
+     * Generate image headers.
+     */
+    public function headers()
+    {
+        header('Content-type: ' . $this->getContentType());
+    }
+
+    /**
+     * Return the content type for this image.
+     *
+     * @return string  The content type for this image.
+     */
+    public function getContentType()
+    {
+        return 'image/' . $this->_type;
+    }
+
+    /**
+     * Getter for the simplified image type.
+     *
+     * @return string  The type of image (png, jpg, etc...)
+     */
+    public function getType()
+    {
+        return $this->_type;
+    }
+
+    /**
+     * Draw a shaped point at the specified (x,y) point. Useful for
+     * scatter diagrams, debug points, etc. Draws squares, circles,
+     * diamonds, and triangles.
+     *
+     * @param integer $x     The x coordinate of the point to brush.
+     * @param integer $y     The y coordinate of the point to brush.
+     * @param string $color  The color to brush the point with.
+     * @param string $shape  What brush to use? Defaults to a square.
+     */
+    public function brush($x, $y, $color = 'black', $shape = 'square')
+    {
+        switch ($shape) {
+        case 'triangle':
+            $verts[0] = array('x' => $x + 3, 'y' => $y + 3);
+            $verts[1] = array('x' => $x, 'y' => $y - 3);
+            $verts[2] = array('x' => $x - 3, 'y' => $y + 3);
+            $this->polygon($verts, $color, $color);
+            break;
+
+        case 'circle':
+            $this->circle($x, $y, 3, $color, $color);
+            break;
+
+        case 'diamond':
+            $verts[0] = array('x' => $x - 3, 'y' => $y);
+            $verts[1] = array('x' => $x, 'y' => $y + 3);
+            $verts[2] = array('x' => $x + 3, 'y' => $y);
+            $verts[3] = array('x' => $x, 'y' => $y - 3);
+            $this->polygon($verts, $color, $color);
+            break;
+
+        case 'square':
+        default:
+            $this->rectangle($x - 2, $y - 2, 4, 4, $color, $color);
+            break;
+        }
+    }
+
+    /**
+     * Add an observer to this image. The observer will be notified
+     * when the image's changes.
+     */
+    public function addObserver($method, $object)
+    {
+        $this->_observers[] = array($method, $object);
+    }
+
+    /**
+     * Let observers know that something happened worth acting on.
+     */
+    public function notifyObservers()
+    {
+        for ($i = 0; $i < count($this->_observers); ++$i) {
+            $obj = $this->_observers[$i][1];
+            $method = $this->_observers[$i][0];
+            $obj->$method($this);
+        }
+    }
+
+    /**
+     * Reset the image data to defaults.
+     */
+    public function reset()
+    {
+        $this->_data = '';
+        $this->_id = '';
+        $this->_width = null;
+        $this->_height = null;
+        $this->_background = 'white';
+        $this->_type = 'png';
+    }
+
+    /**
+     * Get the height and width of the current image data.
+     *
+     * @return array  An hash with 'width' containing the width,
+     *                'height' containing the height of the image.
+     */
+    public function getDimensions()
+    {
+        // Check if we know it already
+        if ($this->_width == 0 && $this->_height == 0) {
+            $tmp = $this->toFile();
+            $details = @getimagesize($tmp);
+            list($this->_width, $this->_height) = $details;
+            unlink($tmp);
+        }
+
+        return array('width' => $this->_width,
+                     'height' => $this->_height);
+    }
+
+    /**
+     * Load the image data from a string.
+     *
+     * @param string $id          An arbitrary id for the image.
+     * @param string $image_data  The data to use for the image.
+     */
+    public function loadString($id, $image_data)
+    {
+        if ($id != $this->_id) {
+            $this->reset();
+            $this->_data = $image_data;
+            $this->_id = $id;
+        }
+    }
+
+    /**
+     * Load the image data from a file.
+     *
+     * @param string $filename  The full path and filename to the file to load
+     *                          the image data from. The filename will also be
+     *                          used for the image id.
+     *
+     * @return mixed  True if successful or already loaded, PEAR Error if file
+     *                does not exist or could not be loaded.
+     */
+    public function loadFile($filename)
+    {
+        if ($filename != $this->_id) {
+            $this->reset();
+            if (!file_exists($filename)) {
+                return PEAR::raiseError('The image file ' . $filename . ' does not exist.');
+            }
+            if ($this->_data = file_get_contents($filename)) {
+                $this->_id = $filename;
+            } else {
+                return PEAR::raiseError('Could not load the image file ' . $filename);
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * Ouputs image data to file.  If $data is false, outputs current
+     * image data after performing any pending operations on the data.
+     * If $data contains raw image data, outputs that data to file without
+     * regard for $this->_data
+     *
+     * @param mixed  String of binary image data | false
+     *
+     * @return string  Path to temporary file.
+     */
+    public function toFile($data = false)
+    {
+        $tmp = Horde_Util::getTempFile('img', false, $this->_tmpdir);
+        $fp = @fopen($tmp, 'wb');
+        fwrite($fp, $data ? $data : $this->raw());
+        fclose($fp);
+        return $tmp;
+    }
+
+    /**
+     * Display the current image.
+     */
+    public function display()
+    {
+        $this->headers();
+        echo $this->raw();
+    }
+
+    /**
+     * Returns the raw data for this image.
+     *
+     * @param boolean $convert  If true, the image data will be returned in the
+     *                          target format, independently from any image
+     *                          operations.
+     *
+     * @return string  The raw image data.
+     */
+    public function raw($convert = false)
+    {
+        return $this->_data;
+    }
+
+    /**
+     * Attempts to apply requested effect to this image.  If the
+     * effect cannot be found a PEAR_Error is returned.
+     *
+     * @param string $type    The type of effect to apply.
+     * @param array $params   Any parameters for the effect.
+     *
+     * @return mixed  true on success | PEAR_Error on failure.
+     */
+    public function addEffect($type, $params)
+    {
+        $class = str_replace('Horde_Image_', '', get_class($this));
+        $effect = Horde_Image_Effect::factory($type, $class, $params);
+        if (is_a($effect, 'PEAR_Error')) {
+            return $effect;
+        }
+        $effect->setImageObject($this);
+        return $effect->apply();
+    }
+
+    /**
+     * Load a list of available effects for this driver.
+     */
+    public function getLoadedEffects()
+    {
+        if (empty($this->_loadedEffects)) {
+            $class = str_replace('Horde_Image_', '', get_class($this));
+
+            // First, load the driver-agnostic Effects.
+            $path = dirname(__FILE__) . '/Image/Effect/';
+            if (is_dir($path)) {
+                if ($handle = opendir($path)) {
+                    while (($file = readdir($handle)) !== false) {
+                        if (substr($file, -4, 4) == '.php') {
+                            $this->_loadedEffects[] = substr($file, 0, strlen($file) - 4);
+                        }
+                    }
+                }
+            }
+
+            // Driver specific effects.
+            $path = $path . $class;
+            if (is_dir($path)) {
+                if ($handle = opendir($path)) {
+                    while (($file = readdir($handle)) !== false) {
+                        if (substr($file, -4, 4) == '.php') {
+                            $this->_loadedEffects[] = substr($file, 0, strlen($file) - 4);
+                        }
+                    }
+                }
+            }
+        }
+
+        return $this->_loadedEffects;
+    }
+
+    /**
+     * Apply any effects in the effect queue.
+     */
+    public function applyEffects()
+    {
+        $this->raw();
+    }
+
+    public function getTmpDir()
+    {
+        return $this->_tmpdir;
+    }
+
+    /**
+     * Utility function to zero out cached geometry information. Shouldn't
+     * really be called from client code, but is needed since Effects may need
+     * to clear these.
+     *
+     */
+    public function clearGeometry()
+    {
+        $this->_height = 0;
+        $this->_width = 0;
+    }
+
+    protected function _logDebug($message)
+    {
+        if (!empty($this->_logger)) {
+            $this->_logger->debug($message);
+        }
+    }
+
+    protected function _logErr($message)
+    {
+        if (!empty($this->_logger)) {
+            $this->_logger->err($message);
+        }
+    }
+
+}
index 2841de1..a1f3b38 100644 (file)
@@ -13,7 +13,7 @@
  * @author  Michael J. Rubinsky <mrubinsk@horde.org>
  * @package Horde_Image
  */
-class Horde_Image_Gd extends Horde_Image
+class Horde_Image_Gd extends Horde_Image_Base
 {
 
     /**
@@ -712,20 +712,20 @@ class Horde_Image_Gd extends Horde_Image
         $r = $round * 2;
 
         // Calculate the upper left arc.
-        $p1 = self::_arcPoints($round, 180, 225);
-        $p2 = self::_arcPoints($round, 225, 270);
+        $p1 = Horde_Image::arcPoints($round, 180, 225);
+        $p2 = Horde_Image::arcPoints($round, 225, 270);
 
         // Calculate the upper right arc.
-        $p3 = self::_arcPoints($round, 270, 315);
-        $p4 = self::_arcPoints($round, 315, 360);
+        $p3 = Horde_Image::arcPoints($round, 270, 315);
+        $p4 = Horde_Image::arcPoints($round, 315, 360);
 
         // Calculate the lower right arc.
-        $p5 = self::_arcPoints($round, 0, 45);
-        $p6 = self::_arcPoints($round, 45, 90);
+        $p5 = Horde_Image::arcPoints($round, 0, 45);
+        $p6 = Horde_Image::arcPoints($round, 45, 90);
 
         // Calculate the lower left arc.
-        $p7 = self::_arcPoints($round, 90, 135);
-        $p8 = self::_arcPoints($round, 135, 180);
+        $p7 = Horde_Image::arcPoints($round, 90, 135);
+        $p8 = Horde_Image::arcPoints($round, 135, 180);
 
         // Draw the corners - upper left, upper right, lower right,
         // lower left.
index 7a14dcf..dc3f463 100644 (file)
@@ -12,7 +12,7 @@
  * @author  Michael J. Rubinsky <mrubinsk@horde.org>
  * @package Horde_Image
  */
-class Horde_Image_Im extends Horde_Image
+class Horde_Image_Im extends Horde_Image_Base
 {
     /**
      * Capabilites of this driver.
@@ -405,9 +405,9 @@ class Horde_Image_Im extends Horde_Image
 
         // If filled, draw the outline.
         if (!empty($fill)) {
-            list($x1, $y1) = $this->_circlePoint($start, $r * 2);
-            list($x2, $y2) = $this->_circlePoint($mid, $r * 2);
-            list($x3, $y3) = $this->_circlePoint($end, $r * 2);
+            list($x1, $y1) = Horde_Image::circlePoint($start, $r * 2);
+            list($x2, $y2) = Horde_Image::circlePoint($mid, $r * 2);
+            list($x3, $y3) = Horde_Image::circlePoint($end, $r * 2);
 
             // This seems to result in slightly better placement of
             // pie slices.
index 0948275..dfbb623 100644 (file)
@@ -10,7 +10,7 @@
  * @author  Michael J. Rubinsky <mrubinsk@horde.org>
  * @package Horde_Image
  */
-class Horde_Image_Imagick extends Horde_Image
+class Horde_Image_Imagick extends Horde_Image_Base
 {
     protected $_imagick;
 
index feef196..9e37d4b 100644 (file)
@@ -12,7 +12,7 @@
  * @author  Mike Cochrane <mike@graftonhall.co.nz>
  * @package Horde_Image
  */
-class Horde_Image_Png extends Horde_Image {
+class Horde_Image_Png extends Horde_Image_Base {
 
     /**
      * The array of pixel data.
index 36517b7..7e8ff02 100644 (file)
@@ -10,7 +10,7 @@
  * @author  Chuck Hagenbuch <chuck@horde.org>
  * @package Horde_Image
  */
-class Horde_Image_Svg extends Horde_Image
+class Horde_Image_Svg extends Horde_Image_Base
 {
     protected $_svg;
 
@@ -308,18 +308,18 @@ class Horde_Image_Svg extends Horde_Image
             $path .= "M $x,$y ";
 
             // Draw out to ellipse edge.
-            list($arcX, $arcY) = $this->_circlePoint($start, $r * 2);
+            list($arcX, $arcY) = Horde_Image::circlePoint($start, $r * 2);
             $path .= 'L ' . round($x + $arcX) . ',' .
                 round($y + $arcY) . ' ';
         }
 
         // Draw arcs.
-        list($arcX, $arcY) = $this->_circlePoint($mid, $r * 2);
+        list($arcX, $arcY) = Horde_Image::circlePoint($mid, $r * 2);
         $path .= "A $r,$r 0 0 1 " .
             round($x + $arcX) . ',' .
             round($y + $arcY) . ' ';
 
-        list($arcX, $arcY) = $this->_circlePoint($end, $r * 2);
+        list($arcX, $arcY) = Horde_Image::circlePoint($end, $r * 2);
         $path .= "A $r,$r 0 0 1 " .
             round($x + $arcX) . ',' .
             round($y + $arcY) . ' ';
index a8cf116..2e83bbf 100644 (file)
@@ -11,7 +11,7 @@
  * @author  Chuck Hagenbuch <chuck@horde.org>
  * @package Horde_Image
  */
-class Horde_Image_Swf extends Horde_Image {
+class Horde_Image_Swf extends Horde_Image_Base {
 
     /**
      * Capabilites of this driver.
@@ -275,8 +275,8 @@ class Horde_Image_Swf extends Horde_Image {
         $y4 = $y + $height - $round;
 
         // Start in the upper left.
-        $p1 = $this->_arcPoints($round, 180, 225);
-        $p2 = $this->_arcPoints($round, 225, 270);
+        $p1 = Horde_Image::arcPoints($round, 180, 225);
+        $p2 = Horde_Image::arcPoints($round, 225, 270);
 
         // Start at the lower left corner of the top left curve.
         $s->movePenTo($x1 + $p1['x1'], $y1 + $p1['y1']);
@@ -286,8 +286,8 @@ class Horde_Image_Swf extends Horde_Image {
         $s->drawCurveTo($x1 + $p2['x3'], $y1 + $p2['y3'], $x1 + $p2['x2'], $y1 + $p2['y2']);
 
         // Calculate the upper right points.
-        $p3 = $this->_arcPoints($round, 270, 315);
-        $p4 = $this->_arcPoints($round, 315, 360);
+        $p3 = Horde_Image::arcPoints($round, 270, 315);
+        $p4 = Horde_Image::arcPoints($round, 315, 360);
 
         // Connect the top left and right curves.
         $s->drawLineTo($x2 + $p3['x1'], $y2 + $p3['y1']);
@@ -297,8 +297,8 @@ class Horde_Image_Swf extends Horde_Image {
         $s->drawCurveTo($x2 + $p4['x3'], $y2 + $p4['y3'], $x2 + $p4['x2'], $y2 + $p4['y2']);
 
         // Calculate the lower right points.
-        $p5 = $this->_arcPoints($round, 0, 45);
-        $p6 = $this->_arcPoints($round, 45, 90);
+        $p5 = Horde_Image::arcPoints($round, 0, 45);
+        $p6 = Horde_Image::arcPoints($round, 45, 90);
 
         // Connect the top right and lower right curves.
         $s->drawLineTo($x3 + $p5['x1'], $y3 + $p5['y1']);
@@ -308,8 +308,8 @@ class Horde_Image_Swf extends Horde_Image {
         $s->drawCurveTo($x3 + $p6['x3'], $y3 + $p6['y3'], $x3 + $p6['x2'], $y3 + $p6['y2']);
 
         // Calculate the lower left points.
-        $p7 = $this->_arcPoints($round, 90, 135);
-        $p8 = $this->_arcPoints($round, 135, 180);
+        $p7 = Horde_Image::arcPoints($round, 90, 135);
+        $p8 = Horde_Image::arcPoints($round, 135, 180);
 
         // Connect the bottom right and bottom left curves.
         $s->drawLineTo($x4 + $p7['x1'], $y4 + $p7['y1']);
@@ -436,7 +436,7 @@ class Horde_Image_Swf extends Horde_Image {
         }
 
         if ($end - $start <= 45) {
-            $pts = $this->_arcPoints($r, $start, $end);
+            $pts = Horde_Image::arcPoints($r, $start, $end);
             $s->movePenTo($x, $y);
             $s->drawLineTo($pts['x1'] + $x, $pts['y1'] + $y);
             $s->drawCurveTo($pts['x3'] + $x, $pts['y3'] + $y, $pts['x2'] + $x, $pts['y2'] + $y);
@@ -444,7 +444,7 @@ class Horde_Image_Swf extends Horde_Image {
         } else {
             $sections = ceil(($end - $start) / 45);
             for ($i = 0; $i < $sections; $i++) {
-                $pts = $this->_arcPoints($r, $start + ($i * 45), ($start + (($i + 1) * 45) > $end)
+                $pts = Horde_Image::arcPoints($r, $start + ($i * 45), ($start + (($i + 1) * 45) > $end)
                                          ? $end
                                          : ($start + (($i + 1) * 45)));
 
index 5f2ca1d..9c52463 100644 (file)
@@ -96,6 +96,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
       <file name="Swf.php" role="php" />
       <file name="Exif.php" role="php" />
       <file name="Exception.php" role="php" />
+      <file name="Base.php" role="php" />
      </dir> <!-- /Horde/Image -->
      <file name="Image.php" role="php" />
     </dir> <!-- /Horde -->
@@ -170,6 +171,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/Image/Svg.php" as="Horde/Image/Svg.php" />
    <install name="lib/Horde/Image/Swf.php" as="Horde/Image/Swf.php" />
    <install name="lib/Horde/Image/Exception.php" as="Horde/Image/Exception.php" />
+   <install name="lib/Horde/Image/Base.php" as="Horde/Image/Base.php" />
    <install name="lib/Horde/Image.php" as="Horde/Image.php" />
   </filelist>
  </phprelease>