Various changes to make the PNG Image driver work.
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 25 May 2010 19:57:18 +0000 (13:57 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 25 May 2010 19:58:49 +0000 (13:58 -0600)
Using EmptyIterator as the default makes it easier for the non
iterable-drivers to fulfill abstract requirements (no need to define the
various Iterable functions)

framework/Image/lib/Horde/Image/Base.php
framework/Image/lib/Horde/Image/Gd.php
framework/Image/lib/Horde/Image/Png.php

index 6854803..f914cb7 100644 (file)
@@ -16,7 +16,7 @@
  * @TODO: - Can we depend on the Horde_Util:: class or some other solution needed?
  *        - Exceptions
  */
-abstract class Horde_Image_Base Implements Iterator
+abstract class Horde_Image_Base extends EmptyIterator
 {
     /**
      * Background color.
@@ -91,6 +91,8 @@ abstract class Horde_Image_Base Implements Iterator
      * Constructor.
      *
      * @param string $rgb  The base color for generated pixels/images.
+     *
+     * @throws InvalidArgumentException
      */
     protected function __construct($params, $context = array())
     {
index 9701cf7..6c1234a 100644 (file)
@@ -789,46 +789,6 @@ class Horde_Image_Gd extends Horde_Image_Base
     }
 
     /**
-     * Return the current image from the internal iterator.
-     *
-     * @return Horde_Image_Gd
-     */
-    public function current()
-    {
-        return clone($this);
-    }
-
-    /**
-     * Get the index of the internal iterator.
-     *
-     * @return integer
-     */
-    public function key()
-    {
-        return 0;
-    }
-
-    /**
-     * Advance the iterator
-     *
-     * @return Horde_Image_Imagick
-     */
-    public function next()
-    {
-        return null;
-    }
-
-    /**
-     * Deterimines if the current iterator item is valid.
-     *
-     * @return boolean
-     */
-    public function valid()
-    {
-        return false;
-    }
-
-    /**
      * Request a specific image from the collection of images.
      *
      * @param integer $index  The index to return
index b42234a..aa9e4bd 100644 (file)
@@ -59,9 +59,9 @@ class Horde_Image_Png extends Horde_Image_Base {
     /**
      * PNG image constructor.
      */
-    function Horde_Image_png($params)
+    public function __construct($params, $context = array())
     {
-        parent::Horde_Image($params);
+        parent::__construct($params, $context);
 
         if (!empty($params['width'])) {
             $this->rectangle(0, 0, $params['width'], $params['height'], $this->_background, $this->_background);
@@ -115,9 +115,9 @@ class Horde_Image_Png extends Horde_Image_Base {
      */
     function rectangle($x, $y, $width, $height, $color = 'black', $fill = 'none')
     {
-        list($r, $g, $b) = $this->getRGB($color);
+        list($r, $g, $b) = Horde_Image::getRGB($color);
         if ($fill != 'none') {
-            list($fR, $fG, $fB) = $this->getRGB($fill);
+            list($fR, $fG, $fB) = Horde_Image::getRGB($fill);
         }
 
         $x2 = $x + $width;
@@ -237,4 +237,31 @@ class Horde_Image_Png extends Horde_Image_Base {
         return pack('N', (($s2 << 16) | $s1));
     }
 
+    /**
+     * Request a specific image from the collection of images.
+     *
+     * @param integer $index  The index to return
+     *
+     * @return Horde_Image_Base
+     * @throws Horde_Image_Exception
+     */
+    public function getImageAtIndex($index)
+    {
+        if ($index > 0) {
+            throw new Horde_Image_Exception('Image index out of bounds.');
+        }
+
+        return clone($this);
+    }
+
+    /**
+     * Return the number of image pages available in the image object.
+     *
+     * @return integer
+     */
+    public function getImagePageCount()
+    {
+        return 1;
+    }
+
 }