*/
static public function getImageObject($params = array())
{
- global $conf;
- $context = array('tmpdir' => Horde::getTempDir(),
- 'logger' => $GLOBALS['injector']->getInstance('Horde_Log_Logger'));
- if (!empty($conf['image']['convert'])) {
- $context['convert'] = $conf['image']['convert'];
- $context['identify'] = $conf['image']['identify'];
- }
- $params = array_merge(array('type' => $conf['image']['type'],
- 'context' => $context),
- $params);
-
- $driver = $conf['image']['driver'];
- return Horde_Image::factory($driver, $params);
+ return $GLOBALS['injector']
+ ->getInstance('Horde_Core_Factory_Image')
+ ->create(array('type' => $GLOBALS['conf']['image']['type']));
}
/**
$p = hash('md5', $user);
$vfspath = Folks::VFS_PATH . '/' . substr(str_pad($p, 2, 0, STR_PAD_LEFT), -2) . '/';
$vfs_name = $p . '.' . $conf['images']['image_type'];
- $driver = $conf['image']['driver'];
- $context = array('tmpdir' => Horde::getTempDir());
- if (!empty($conf['image']['convert'])) {
- $context['convert'] = $conf['image']['convert'];
- $context['identify'] = $conf['image']['identify'];
- }
- $img = Horde_Image::factory($driver,
- array('type' => $conf['images']['image_type'],
- 'context' => $context));
try {
+ $img = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Image')->create(array('type' => $conf['images']['image_type']));
$result = $img->loadFile($file);
- } catch (Horde_Image_Exception $e) {
+ } catch (Horde_Exception $e) {
throw new Horde_Exception_Prior($e);
}
$dimensions = $img->getDimensions();
--- /dev/null
+<?php
+/**
+ * @category Horde
+ * @package Core
+ */
+class Horde_Core_Factory_Image
+{
+ /**
+ * The injector.
+ *
+ * @var Horde_Injector
+ */
+ private $_injector;
+
+ /**
+ * Constructor.
+ *
+ * @param Horde_Injector $injector The injector to use.
+ */
+ public function __construct(Horde_Injector $injector)
+ {
+ $this->_injector = $injector;
+ }
+
+ /**
+ * Returns an appropriate Horde_Image object based on Horde's configuration.
+ *
+ * @param array $params An array of image parameters. @see Horde_Image_Base
+ * @return Horde_Image
+ * @throws Horde_Exception
+ */
+ public function create(array $params = array())
+ {
+ global $conf;
+
+ $driver = $conf['image']['driver'];
+ $context = array(
+ 'tmpdir' => Horde::getTempdir(),
+ 'logger' => $this->_injector->getInstance('Horde_Log_Logger'));
+ if ($driver == 'Im') {
+ $context['convert'] = $conf['image']['convert'];
+ $context['identify'] = $conf['image']['identify'];
+ }
+ // Use the default
+ $class = 'Horde_Image_' . $driver;
+ if (class_exists($class)) {
+ return new $class($params, $context);
+ } else {
+ throw new Horde_Exception('Invalid Image driver specified: ' . $class . ' not found.');
+ }
+ }
+
+}
\ No newline at end of file
<email>slusarz@horde.org</email>
<active>yes</active>
</developer>
- <date>2010-10-22</date>
- <time>13:14:28</time>
+ <date>2010-10-25</date>
+ <time>09:15:23</time>
<version>
<release>0.1.0</release>
<api>0.1.0</api>
<file name="History.php" role="php" />
<file name="HttpClient.php" role="php" />
<file name="Identity.php" role="php" />
+ <file name="Image.php" role="php" />
<file name="Imple.php" role="php" />
<file name="KolabServer.php" role="php" />
<file name="KolabSession.php" role="php" />
<install as="Horde/Core/Factory/History.php" name="lib/Horde/Core/Factory/History.php" />
<install as="Horde/Core/Factory/HttpClient.php" name="lib/Horde/Core/Factory/HttpClient.php" />
<install as="Horde/Core/Factory/Identity.php" name="lib/Horde/Core/Factory/Identity.php" />
+ <install as="Horde/Core/Factory/Image.php" name="lib/Horde/Core/Factory/Image.php" />
<install as="Horde/Core/Factory/Imple.php" name="lib/Horde/Core/Factory/Imple.php" />
<install as="Horde/Core/Factory/KolabServer.php" name="lib/Horde/Core/Factory/KolabServer.php" />
<install as="Horde/Core/Factory/KolabSession.php" name="lib/Horde/Core/Factory/KolabSession.php" />
<release>beta</release>
<api>beta</api>
</stability>
- <date>2010-10-22</date>
+ <date>2010-10-25</date>
<license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
<notes>
* Add Horde_Session.
* (optional)data - The image binary data.
*</pre>
* @param array $context The object context - configuration, injected objects
- *
+ *<pre>
+ * (required)tmpdir - Temporary directory
+ * (optional)logger - The logger
+ *</pre>
* @throws InvalidArgumentException
*/
protected function __construct($params, $context = array())
}
if (!empty($params['type'])) {
// We only want the extension, not the full mimetype.
- if (strpos($type, 'image/') !== false) {
- $type = substr($type, 6);
+ if (strpos($params['type'], 'image/') !== false) {
+ $params['type'] = substr($params['type'], 6);
}
$this->_type = $params['type'];
}
'convert' => $this->_image->getConvertPath());
$size = $image->getDimensions();
- $new = Horde_Image::factory('im', array('data' => $image->raw(), 'context' => $context));
+ $new = new Horde_Image_Im(array('data' => $image->raw()), $context);
$new->addEffect('RoundCorners', array('border' => 2, 'bordercolor' => '#111', 'background' => 'none'));
$new->applyEffects();
{
$context = array('tmpdir' => $this->_image->getTmpDir());
$size = $image->getImageGeometry();
- $new = Horde_Image::factory('Imagick', array('context' => $context));
+ $new = new Horde_Image_Imagick(array(), $context);
$new->loadString($image->getImageBlob());
$image->destroy();
$new->addEffect('RoundCorners', array('border' => 2, 'bordercolor' => '#111'));
'convert' => $GLOBALS['convert'],
'logger' => $GLOBALS['injector']->getInstance('Horde_Log_Logger'),
'identify' => $GLOBALS['identify']);
- $params['context'] = $context;
- return Horde_Image::factory($GLOBALS['driver'], $params);
+ return new Horde_Image_Im($params, $context);
}
function logThis($effect, $time, $memory)
}
/* Load the image object. */
-$context = array('tmpdir' => Horde::getTempDir());
-$driver = $conf['image']['driver'];
-if (!empty($conf['image']['convert'])) {
- $context['convert'] = $conf['image']['convert'];
- $context['identify'] = $conf['image']['identify'];
-}
$type = Horde_Mime_Magic::analyzeData($file_data);
-$image = Horde_Image::factory($driver,
- array('context' => $context));
-$image->loadString($file_data);
-$image->setType($type);
+$image = $GLOBALS['injector']
+ ->getInstance('Horde_Core_Factory_Image')
+ ->create(array('type' => $type,
+ 'data' => $file_data));
+
/* Check if no editing action required and send the image to browser. */
if (empty($action)) {
$image->display();
'/' => '010100010'
);
-$image = Horde_Image::factory($vars->get('type', 'Png'), array(
+$image = new Horde_Image_Png(array(
'background' => 'white',
'context' => array(
'tmpdir' => Horde::getTempDir()
),
'height' => $height,
- 'width' => $width
-));
+ 'width' => $width));
$xpos = 0;
for ($idx = 0; $idx < $textlen; ++$idx) {
//@TODO: Pass in a Horde_Logger in $context if desired.
$context = array('tmpdir' => Horde::getTempDir());
try {
- if (!empty($GLOBALS['conf']['image']['convert'])) {
- $context['convert'] = $GLOBALS['conf']['image']['convert'];
- $context['identify'] = $GLOBALS['conf']['image']['identify'];
- }
- $img = Horde_Image::factory($GLOBALS['conf']['image']['driver'], array('context' => $context));
- } catch (Horde_Image_Exception $e) {
+ $img = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Image')->create();
+ } catch (Horde_Exception $e) {
return false;
}
return false;
}
- $context = array('tmpdir' => Horde::getTempdir());
- if (!empty($GLOBALS['conf']['image']['convert'])) {
- $context['convert'] = $GLOBALS['conf']['image']['convert'];
- $context['identify'] = $GLOBALS['conf']['image']['identify'];
- }
try {
- $img = Horde_Image::factory($GLOBALS['conf']['image']['driver'], array('context' => $context));
- } catch (Horde_Image_Exception $e) {
+ $img = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Image')->create();
+ } catch (Horde_Exception $e) {
return false;
}
if (!$img->hasCapability('multipage') && !$img->hasCapability('pdf')) {