Index: Image.php =================================================================== --- Image.php (revision 11372) +++ Image.php (working copy) @@ -335,7 +335,33 @@ */ public function generate() { - $id = parent::generate(); + // try count for unique name generation + $trys = 2; + + do { + $id = parent::generate(); + + // file does not exist, exit loop + if (!file_exists($this->_imgDir.$id.'.png')) { + break; + } + + // a file with that name exists, retry + $trys--; + } + // do until trys are used up + while(true === (bool) $trys); + + if (false === (bool) $trys) { + /** + * @see Zend_Form_Exception + */ + require_once 'Zend/Form/Exception.php'; + + throw new Zend_Form_Exception("Unable to generate unique filename."); + } + + $this->_generateImage($id, $this->getWord()); if (mt_rand(0, $this->getGcFreq()) == 1) {