From: Michael J. Rubinsky Date: Sat, 23 Oct 2010 14:35:11 +0000 (-0400) Subject: Allow passing the image data and type directly in the const'r also. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=2b386ff604540522c80b96bde3e0f57a5b6e0195;p=horde.git Allow passing the image data and type directly in the const'r also. --- diff --git a/framework/Image/lib/Horde/Image/Base.php b/framework/Image/lib/Horde/Image/Base.php index 0ba250778..1a7c27f10 100644 --- a/framework/Image/lib/Horde/Image/Base.php +++ b/framework/Image/lib/Horde/Image/Base.php @@ -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: + *
+     *   (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.
+     *
+ * @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; } diff --git a/framework/Image/lib/Horde/Image/Gd.php b/framework/Image/lib/Horde/Image/Gd.php index 74a0e61de..4bf319388 100644 --- a/framework/Image/lib/Horde/Image/Gd.php +++ b/framework/Image/lib/Horde/Image/Gd.php @@ -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))); } diff --git a/framework/Image/lib/Horde/Image/Im.php b/framework/Image/lib/Horde/Image/Im.php index 563277b7a..ceba57802 100644 --- a/framework/Image/lib/Horde/Image/Im.php +++ b/framework/Image/lib/Horde/Image/Im.php @@ -85,6 +85,8 @@ class Horde_Image_Im extends Horde_Image_Base /** * Constructor. + * + * @see Horde_Image_Base::_construct */ public function __construct($params, $context = array()) { diff --git a/framework/Image/lib/Horde/Image/Imagick.php b/framework/Image/lib/Horde/Image/Imagick.php index 3df072fcb..7f7aafbb3 100644 --- a/framework/Image/lib/Horde/Image/Imagick.php +++ b/framework/Image/lib/Horde/Image/Imagick.php @@ -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()) {