Remove the $id parameter from loadString and loadFile
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 20 Feb 2010 19:59:56 +0000 (14:59 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 20 Feb 2010 20:36:23 +0000 (15:36 -0500)
It's not necessary, client code should know that it has loaded data, it
was causing all kinds of problems with Image effects, and takes up resources.

ansel/lib/Faces/Base.php
ansel/lib/Image.php
framework/Image/lib/Horde/Image/Base.php
framework/Image/lib/Horde/Image/Effect/Imagick/PhotoStack.php
framework/Image/lib/Horde/Image/Gd.php
framework/Image/lib/Horde/Image/Im.php
framework/Image/lib/Horde/Image/Imagick.php
horde/services/images/view.php
imp/lib/Mime/Viewer/Images.php
imp/lib/Mime/Viewer/Pdf.php

index 16d2083..648b0a2 100644 (file)
@@ -380,7 +380,7 @@ class Ansel_Faces_Base
         if ($data instanceof PEAR_Error) {
             throw new Horde_Exception_Prior($data);
         }
-        $img->loadString($face_id, $data);
+        $img->loadString($data);
 
         return $img;
     }
index 6944c80..696de4a 100644 (file)
@@ -284,7 +284,7 @@ class Ansel_Image Implements Iterator
         // already have the full data loaded. If we auto-rotate the image
         // then there is no need to save it just to load it again.
         if ($view == 'full' && !empty($this->_data['full'])) {
-            $this->_image->loadString('original', $this->_data['full']);
+            $this->_image->loadString($this->_data['full']);
             $this->_loaded['full'] = true;
             return true;
         }
@@ -302,9 +302,6 @@ class Ansel_Image Implements Iterator
             return;
         }
 
-        /* We've definitely successfully loaded the image now. */
-        $this->_loaded[$viewHash] = true;
-
         /* Get the VFS info. */
         $vfspath = $this->getVFSPath($view, $style);
 
@@ -315,8 +312,11 @@ class Ansel_Image Implements Iterator
             throw new Ansel_Exception($data);
         }
 
+        /* We've definitely successfully loaded the image now. */
+        $this->_loaded[$viewHash] = true;
         $this->_data[$viewHash] = $data;
-        $this->_image->loadString($vfspath . '/' . $this->id, $data);
+        $this->_image->loadString($data);
+
         return true;
     }
 
@@ -392,7 +392,9 @@ class Ansel_Image Implements Iterator
             Horde::logMessage($data, __FILE__, __LINE__, PEAR_LOG_ERR);
             throw new Ansel_Exception($data);
         }
-        $this->_image->loadString($this->getVFSPath('full') . '/' . $this->id, $data);
+
+        $vHash = $this->getViewHash($view, $style);
+        $this->_image->loadString($data);
         $styleDef = Ansel::getStyleDefinition($style);
         if ($view == 'prettythumb') {
             $viewType = $styleDef['thumbstyle'];
@@ -419,17 +421,16 @@ class Ansel_Image Implements Iterator
         $iview->create();
 
         /* Cache the data from the new imageview */
-        $view = $this->getViewHash($view, $style);
         try {
-            $this->_data[$view] = $this->_image->raw();
+            $this->_data[$vHash] = $this->_image->raw();
         } catch (Horde_Image_Exception $e) {
             throw new Ansel_Exception($e);
         }
 
         /* ...and put it in Horde_Image obejct, then save */
-        $this->_image->loadString($vfspath . '/' . $this->id, $this->_data[$view]);
-        $this->_loaded[$view] = true;
-        $GLOBALS['ansel_vfs']->writeData($vfspath, $this->getVFSName($view), $this->_data[$view], true);
+        $this->_image->loadString($this->_data[$vHash]);
+        $this->_loaded[$vHash] = true;
+        $GLOBALS['ansel_vfs']->writeData($vfspath, $this->getVFSName($vHash), $this->_data[$vHash], true);
 
         /* Autowatermark the screen view */
         if ($view == 'screen' &&
@@ -1089,7 +1090,7 @@ class Ansel_Image Implements Iterator
         try {
             $this->_image->addEffect($type, $params);
         } catch (Horde_Image_Exception $e) {
-            Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_DEBUG);
+            Horde::logMessage($e->getMessage(), __FILE__, __LINE__, PEAR_LOG_ERR);
             throw new Ansel_Exception($e);
         }
     }
index 0e97750..0f9b748 100644 (file)
@@ -41,16 +41,6 @@ abstract class Horde_Image_Base Implements Iterator
     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;
@@ -224,7 +214,6 @@ abstract class Horde_Image_Base Implements Iterator
     public function reset()
     {
         $this->_data = '';
-        $this->_id = '';
         $this->_width = null;
         $this->_height = null;
         $this->_background = 'white';
@@ -256,13 +245,10 @@ abstract class Horde_Image_Base Implements Iterator
      * @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)
+    public function loadString($image_data)
     {
-        if ($id != $this->_id) {
-            $this->reset();
-            $this->_data = $image_data;
-            $this->_id = $id;
-        }
+        $this->reset();
+        $this->_data = $image_data;
     }
 
     /**
@@ -278,16 +264,12 @@ abstract class Horde_Image_Base Implements Iterator
      */
     public function loadFile($filename)
     {
-        if ($filename != $this->_id) {
-            $this->reset();
-            if (!file_exists($filename)) {
-                throw new Horde_Image_Exception(sprintf("The image file, %s, does not exist.", $filename));
-            }
-            if ($this->_data = file_get_contents($filename)) {
-                $this->_id = $filename;
-            } else {
-                throw new Horde_Image_Exception(sprintf("Could not load the image file %s", $filename));
-            }
+        $this->reset();
+        if (!file_exists($filename)) {
+            throw new Horde_Image_Exception(sprintf("The image file, %s, does not exist.", $filename));
+        }
+        if (!$this->_data = file_get_contents($filename)) {
+            throw new Horde_Image_Exception(sprintf("Could not load the image file %s", $filename));
         }
 
         return true;
index 3f67e58..60f594d 100644 (file)
@@ -201,7 +201,7 @@ class Horde_Image_Effect_Imagick_PhotoStack extends Horde_Image_Effect
         $context = array('tmpdir' => $this->_image->getTmpDir());
         $size = $image->getImageGeometry();
         $new = Horde_Image::factory('Imagick', array('context' => $context));
-        $new->loadString('somestring', $image->getImageBlob());
+        $new->loadString($image->getImageBlob());
         $image->destroy();
         $new->addEffect('RoundCorners', array('border' => 2, 'bordercolor' => '#111'));
         $new->applyEffects();
index 7e6bd80..a5cee5b 100644 (file)
@@ -175,12 +175,9 @@ class Horde_Image_Gd extends Horde_Image_Base
      * @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)
+    public function loadString($image_data)
     {
-        if ($id != $this->_id) {
-            $this->_im = $this->_call('imageCreateFromString', array($image_data));
-            $this->_id = $id;
-        }
+        $this->_im = $this->_call('imageCreateFromString', array($image_data));
     }
 
     /**
index 2ac9435..439af8d 100644 (file)
@@ -101,7 +101,7 @@ class Horde_Image_Im extends Horde_Image_Base
         if (!empty($params['filename'])) {
             $this->loadFile($params['filename']);
         } elseif (!empty($params['data'])) {
-            $this->loadString(md5($params['data']), $params['data']);
+            $this->loadString($params['data']);
         } else {
             $cmd = "-size {$this->_width}x{$this->_height} xc:{$this->_background} +profile \"*\" {$this->_type}:__FILEOUT__";
             $this->executeConvertCmd($cmd);
index 8db9ea3..0e61c1b 100644 (file)
@@ -60,7 +60,7 @@ class Horde_Image_Imagick extends Horde_Image_Base
         if (!empty($params['filename'])) {
             $this->loadFile($params['filename']);
         } elseif(!empty($params['data'])) {
-            $this->loadString(md5($params['data']), $params['data']);
+            $this->loadString($params['data']);
         } else {
             $this->_width = max(array($this->_width, 1));
             $this->_height = max(array($this->_height, 1));
@@ -82,9 +82,9 @@ class Horde_Image_Imagick extends Horde_Image_Base
      *
      * @return void
      */
-    public function loadString($id, $image_data)
+    public function loadString($image_data)
     {
-        parent::loadString($id, $image_data);
+        parent::loadString($image_data);
         $this->_imagick->clear();
         try {
             $this->_imagick->readImageBlob($image_data);
index add8ba2..011f061 100644 (file)
@@ -74,7 +74,7 @@ if (!empty($conf['image']['convert'])) {
     $context['identify'] = $conf['image']['identify'];
 }
 $image = Horde_Image::factory($driver, array('context' => $context));
-$image->loadString($file, $file_data);
+$image->loadString($file_data);
 
 /* Check if no editing action required and send the image to browser. */
 if (empty($action)) {
index d12763b..9d46bc1 100644 (file)
@@ -272,7 +272,7 @@ EOD;
 
         if ($load) {
             try {
-                $ret = $img->loadString(1, $this->_mimepart->getContents());
+                $ret = $img->loadString($this->_mimepart->getContents());
             } catch (Horde_Image_Exception $e) {
                 return false;
             }
index 39c6369..db1c1d0 100644 (file)
@@ -126,7 +126,7 @@ class IMP_Horde_Mime_Viewer_Pdf extends Horde_Mime_Viewer_Pdf
         
         if ($load) {
             try {
-                $ret = $img->loadString(1, $this->_mimepart->getContents());
+                $ret = $img->loadString($this->_mimepart->getContents());
             } catch (Horde_Image_Exception $e) {
                 return false;
             }