From 60042266979c25b4f2c3bb8cf904184c527a8e1b Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Fri, 19 Feb 2010 11:03:44 -0500 Subject: [PATCH] Always load the image before iterating, but make sure it's not already loaded first. If we attempt to call #load() twice, it will reload the raw data into Horde_Image, thus resetting the iterator and causing an infinite loop. Also, use consistent method names. --- ansel/lib/Gallery.php | 2 +- ansel/lib/Image.php | 32 +++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/ansel/lib/Gallery.php b/ansel/lib/Gallery.php index 9513cf71a..9ad0982b9 100644 --- a/ansel/lib/Gallery.php +++ b/ansel/lib/Gallery.php @@ -233,7 +233,7 @@ class Ansel_Gallery extends Horde_Share_Object_sql_hierarchical /* Check for a supported multi-page image */ if ($image->isMultiPage() === true) { - $params['name'] = $image->getPageCount() . ' page image: ' . $image->filename; + $params['name'] = $image->getImagePageCount() . ' page image: ' . $image->filename; $mGallery = $GLOBALS['ansel_storage']->createGallery($params, $this->getPermission(), $this->getId()); $i = 1; foreach ($image as $page) { diff --git a/ansel/lib/Image.php b/ansel/lib/Image.php index 1db6750e7..a34fddc7a 100644 --- a/ansel/lib/Image.php +++ b/ansel/lib/Image.php @@ -1271,8 +1271,12 @@ class Ansel_Image Implements Iterator * @return integer The number of pages. * @throws Ansel_Exception */ - public function getPageCount() + public function getImagePageCount() { + if (empty($this->_loaded['full'])) { + $this->load(); + } + try { return $this->_image->getImagePageCount(); } catch (Horde_Image_Exception $e) { @@ -1288,7 +1292,9 @@ class Ansel_Image Implements Iterator */ public function rewind() { - $this->load(); + if (empty($this->_loaded['full'])) { + $this->load(); + } try { $this->_image->rewind(); } catch (Horde_Image_Exception $e) { @@ -1303,8 +1309,14 @@ class Ansel_Image Implements Iterator */ public function current() { - $this->load(); - return $this->_buildImageObject($this->_image->current()); + if (empty($this->_loaded['full'])) { + $this->load(); + } + try { + return $this->_buildImageObject($this->_image->current()); + } catch (Horde_Image_Exception $e) { + throw new Ansel_Exception($e); + } } /** @@ -1315,7 +1327,9 @@ class Ansel_Image Implements Iterator */ public function key() { - $this->load(); + if (empty($this->_loaded['full'])) { + $this->load(); + } try { return $this->_image->key(); } catch (Horde_Image_Exception $e) { @@ -1330,7 +1344,9 @@ class Ansel_Image Implements Iterator */ public function next() { - $this->load(); + if (empty($this->_loaded['full'])) { + $this->load(); + } if ($next = $this->_image->next()) { return $this->_buildImageObject($next); } @@ -1346,7 +1362,9 @@ class Ansel_Image Implements Iterator */ public function valid() { - $this->load(); + if (empty($this->_loaded['full'])) { + $this->load(); + } try { return $this->_image->valid(); } catch (Horde_Image_Exception $e) { -- 2.11.0