loadString() public method

Loads the image data from a string.
public loadString ( string $image_data )
$image_data string The data to use for the image.
Esempio n. 1
0
 /**
  * Load image data from a string.
  *
  * @param string $id
  * @param string $image_data
  *
  * @return void
  */
 public function loadString($image_data)
 {
     parent::loadString($image_data);
     $this->_imagick->clear();
     try {
         $this->_imagick->readImageBlob($this->_data);
         $this->_imagick->setImageFormat($this->_type);
         $this->_imagick->setIteratorIndex(0);
     } catch (ImagickException $e) {
         throw new Horde_Image_Exception($e);
     }
     unset($this->_data);
 }
Esempio n. 2
0
 /**
  * Creates and caches the given view.
  *
  * @param string $view         Which view to create.
  * @param Ansel_Style  $style  A style object
  *
  * @throws Ansel_Exception
  */
 public function createView($view, Ansel_Style $style = null, $watermark = '')
 {
     // Default to the gallery's style
     if (empty($style)) {
         $style = $GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($this->gallery)->getStyle();
     }
     // Get the VFS info.
     $vfspath = $this->getVFSPath($view, $style);
     if ($GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->exists($vfspath, $this->getVFSName($view))) {
         return;
     }
     try {
         $data = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->read($this->getVFSPath('full'), $this->getVFSName('full'));
     } catch (Horde_Vfs_Exception $e) {
         Horde::log($e, 'ERR');
         throw new Ansel_Exception($e);
     }
     // Force screen images to ALWAYS be jpegs for performance/size
     if ($view == 'screen' && $GLOBALS['conf']['image']['type'] != 'jpeg') {
         $originalType = $this->_image->setType('jpeg');
     } else {
         $originalType = false;
     }
     $vHash = $this->getViewHash($view, $style);
     $this->_image->loadString($data);
     if ($view == 'thumb') {
         $viewType = $style->thumbstyle;
     } else {
         // Screen, Mini
         $viewType = ucfirst($view);
     }
     try {
         $iview = Ansel_ImageGenerator::factory($viewType, array('image' => $this, 'style' => $style));
     } catch (Ansel_Exception $e) {
         // It could be we don't support the requested effect, try
         // ansel_default before giving up.
         if ($view == 'thumb' && $viewType != 'Thumb') {
             $iview = Ansel_ImageGenerator::factory('Thumb', array('image' => $this, 'style' => Ansel::getStyleDefinition('ansel_default')));
         } else {
             // If it wasn't a thumb, then something else must be wrong
             throw $e;
         }
     }
     // generate the view
     $iview->create();
     // Cache the data from the new ImageGenerator
     try {
         $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($this->_data[$vHash]);
     $this->_loaded[$vHash] = true;
     $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->writeData($vfspath, $this->getVFSName($vHash), $this->_data[$vHash], true);
     // Watermark
     if (!empty($watermark)) {
         $this->watermark($view);
         // Cache the data again
         try {
             $this->_data[$vHash] = $this->_image->raw();
         } catch (Horde_Image_Exception $e) {
             throw new Ansel_Exception($e);
         }
         $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->writeData($vfspath, $this->getVFSName($view), $this->_data[$vHash]);
     }
     // Revert any type change
     if ($originalType) {
         $this->_image->setType($originalType);
     }
 }