Allow passing the image data and type directly in the const'r also.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 23 Oct 2010 14:35:11 +0000 (10:35 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Mon, 25 Oct 2010 13:29:22 +0000 (09:29 -0400)
framework/Image/lib/Horde/Image/Base.php
framework/Image/lib/Horde/Image/Gd.php
framework/Image/lib/Horde/Image/Im.php
framework/Image/lib/Horde/Image/Imagick.php

index 0ba2507..1a7c27f 100644 (file)
@@ -86,7 +86,16 @@ abstract class Horde_Image_Base extends EmptyIterator
     /**
      * Constructor.
      *
-     * @param string $rgb  The base color for generated pixels/images.
+     * @param array $params   The image object parameters. Values include:
+     *<pre>
+     *   (optional)width  - The desired image width
+     *   (optional)height - The desired image height
+     *   (optional)type   - The image type (png, jpeg etc...) If not provided,
+     *                      or set by the setType method, any image output will
+     *                      be converted to the default image type of png.
+     *   (optional)data   - The image binary data.
+     *</pre>
+     * @param array $context  The object context - configuration, injected objects
      *
      * @throws InvalidArgumentException
      */
@@ -107,6 +116,10 @@ abstract class Horde_Image_Base extends EmptyIterator
             $this->_height = $params['height'];
         }
         if (!empty($params['type'])) {
+            // We only want the extension, not the full mimetype.
+            if (strpos($type, 'image/') !== false) {
+                $type = substr($type, 6);
+            }
             $this->_type = $params['type'];
         }
 
@@ -176,6 +189,10 @@ abstract class Horde_Image_Base extends EmptyIterator
      */
     public function setType($type)
     {
+        // We only want the extension, not the full mimetype.
+        if (strpos($type, 'image/') !== false) {
+            $type = substr($type, 6);
+        }
         $this->_type = $type;
     }
 
index 74a0e61..4bf3193 100644 (file)
@@ -47,7 +47,11 @@ class Horde_Image_Gd extends Horde_Image_Base
     public function __construct($params, $context = array())
     {
         parent::__construct($params, $context);
-        if (!empty($params['width'])) {
+        if (!empty($params['filename'])) {
+            $this->loadFile($params['filename']);
+        } elseif (!empty($params['data'])) {
+            $this->loadString($params['data']);
+        } elseif (!empty($params['width'])) {
             $this->_im = $this->create($this->_width, $this->_height);
             $this->call('imageFill', array($this->_im, 0, 0, $this->_allocateColor($this->_background)));
         }
index 563277b..ceba578 100644 (file)
@@ -85,6 +85,8 @@ class Horde_Image_Im extends Horde_Image_Base
 
     /**
      * Constructor.
+     *
+     * @see Horde_Image_Base::_construct
      */
     public function __construct($params, $context = array())
     {
index 3df072f..7f7aafb 100644 (file)
@@ -42,12 +42,10 @@ class Horde_Image_Imagick extends Horde_Image_Base
                                      'canvas',
                                      'multipage',
                                      'pdf');
-
     /**
      * Const'r
      *
-     * @param array $params
-     * @param array $context
+     * @see Horde_Image_Base::_construct
      */
     public function __construct($params, $context = array())
     {