/** * Create and cache the view. * * @return mixed Views used as gallery key images return Horde_Image, * other views return boolean */ public function create() { if (!empty($this->_image)) { // Use Horde_Image since we don't know at this point which // view we have loaded. $img = $this->_image->getHordeImage(); $this->_dimensions = $img->getDimensions(); } return $this->_create(); }
/** * Create and cache the view. * * @return mixed Views used as gallery key images return Horde_Image, * other views return boolean */ public function create() { if (!empty($this->_image)) { // Make sure to load the image. $this->_image->load('full'); $img = $this->_image->getHordeImage(); $this->_dimensions = $img->getDimensions(); } return $this->_create(); }
/** * Create a face image from the given data. * * @param integer $face_id Face id to generate * @param Ansel_Image $image Image face belongs to * @param integer $x1 The top left corner of the cropped image. * @param integer $y1 The top right corner of the cropped image. * @param integer $x2 The bottom left corner of the cropped image. * @param integer $y2 The bottom right corner of the cropped image. * * @throws Ansel_Exception */ public function createView($face_id, Ansel_Image $image, $x1, $y1, $x2, $y2) { // Make sure the image data is fresh $image->load('screen'); // Crop to the face try { $image->crop($x1, $y1, $x2, $y2); } catch (Horde_Image_Exception $e) { throw new Ansel_Exception($e->getMessage()); } // Resize and save $ext = Ansel_Faces::getExtension(); $path = Ansel_Faces::getVFSPath($image->id); $image->resize(50, 50, false); try { $GLOBALS['injector']->getInstance('Horde_Core_Factory_Vfs')->create('images')->writeData($path . 'faces', $face_id . $ext, $image->raw(), true); } catch (Horde_Vfs_Exception $e) { throw new Ansel_Exception($e); } }
/** * Returns the key image for this gallery. * * @param Ansel_Style $style Force the use of this style, if it's available * otherwise use whatever style is choosen for * this gallery. If prettythumbs are not * available then we always use ansel_default * style. * * @return mixed The image_id of the key image or false. */ public function getKeyImage(Ansel_Style $style = null) { if (is_null($style)) { $style = $this->getStyle(); } if ($style->keyimage_type != 'Thumb') { $thumbstyle = $style->keyimage_type; $styleHash = $style->getHash($thumbstyle); // First check for the existence of a key image in the specified style if ($this->get('default_prettythumb')) { $thumbs = @unserialize($this->get('default_prettythumb')); } if (!isset($thumbs) || !is_array($thumbs)) { $thumbs = array(); } if (!empty($thumbs[$styleHash])) { return $thumbs[$styleHash]; } // Don't already have one, must generate it. $params = array('gallery' => $this, 'style' => $style); try { $iview = Ansel_ImageGenerator::factory($style->keyimage_type, $params); $img = $iview->create(); // Note the gallery_id is negative for generated stacks $iparams = array('image_filename' => $this->get('name'), 'image_caption' => $this->get('name'), 'data' => $img->raw(), 'image_sort' => 0, 'gallery_id' => -$this->id); $newImg = new Ansel_Image($iparams); $newImg->save(); $prettyData = serialize(array_merge($thumbs, array($styleHash => $newImg->id))); $this->set('default_prettythumb', $prettyData, true); // Make sure the hash is saved since it might be different then // the gallery's $GLOBALS['injector']->getInstance('Ansel_Storage')->ensureHash($styleHash); return $newImg->id; } catch (Ansel_Exception $e) { // Might not support the requested style...try ansel_default // but protect against infinite recursion. Horde::log($e->getMessage(), 'ERR'); if ($style->keyimage_type != 'plain') { return $this->getKeyImage(Ansel::getStyleDefinition('ansel_default')); } } } else { // We are just using an image thumbnail. if ($this->countImages()) { if ($default = $this->get('default')) { return $default; } $keys = $this->listImages(); $this->set('default', $keys[count($keys) - 1]); $this->set('default_type', 'auto'); $this->save(); return $keys[count($keys) - 1]; } if ($this->hasSubGalleries()) { // Fall through to a key image of a sub gallery. try { $galleries = $GLOBALS['injector']->getInstance('Ansel_Storage')->listGalleries(array('parent' => $this->id, 'all_levels' => false)); foreach ($galleries as $gallery) { if ($default_img = $gallery->getKeyImage($style)) { return $default_img; } } } catch (Ansel_Exception $e) { return false; } } } // Could not find a key image return false; }
/** * Outputs the HTML for an image thumbnail tile. * * @param Ansel_Image $image The Ansel_Image we are displaying. * @param Ansel_Style $style A sytle definiition array. * @param boolean $mini Force the use of a mini thumbnail? * @param array $params Any other paramaters needed by this tile * * @return Outputs the HTML for the image tile. */ public static function getTile(Ansel_Image $image, Ansel_Style $style = null, $mini = false, array $params = array()) { global $conf, $registry, $injector; $page = isset($params['page']) ? $params['page'] : 0; $view_type = isset($params['view']) ? $params['view'] : 'Gallery'; $view = $injector->createInstance('Horde_View'); $view->addTemplatePath(ANSEL_TEMPLATES . '/tile'); $view->image = $image; $view->view_type = $view_type; try { $view->parent = $injector->getInstance('Ansel_Storage')->getGallery($image->gallery); } catch (Ansel_Exception $e) { // @TODO: Short circuit here and return a generic error tile. } catch (Horde_Exception_NotFound $e) { // @TODO: Ditto above. } if (is_null($style)) { $style = $view->parent->getStyle(); } $date = $view->parent->getDate(); if ($view_type == 'Results') { $haveSearch = 1; } else { $haveSearch = 0; } // Override the thumbnail to mini or use style default? $thumbstyle = $mini ? 'mini' : 'thumb'; // URL for image properties/actions $view->image_url = Horde::url('image.php')->add(array_merge(array('gallery' => $image->gallery, 'page' => $page, 'image' => $image->id, 'havesearch' => $haveSearch), $date)); // URL to view the image. This is the link for the Tile. // $view_url is the link for the thumbnail and since this might not // always point to the image view page, we set $img_view_url to link to // the image view $view->img_view_url = Ansel::getUrlFor('view', array_merge(array('gallery' => $image->gallery, 'slug' => $view->parent->get('slug'), 'page' => $page, 'view' => 'Image', 'image' => $image->id, 'havesearch' => $haveSearch), $date)); if (!empty($params['image_view_src'])) { $view->view_url = Ansel::getImageUrl($image->id, 'screen', true); } elseif (empty($params['image_view_url'])) { $view->view_url = new Horde_Url($view->img_view_url); } else { $view->view_url = new Horde_Url(str_replace(array('%i', '%g', '%s'), array($image->id, $image->gallery, $view->parent->get('slug')), urldecode($params['image_view_url']))); // If we override the view_url, assume we want to override this also $view->img_view_url = $view->view_url; } // Need the gallery URL to display the "From" link when showing // the image tile from somewhere other than the gallery view. if (!empty($view_type) || basename($_SERVER['PHP_SELF']) == 'view.php') { $view->gallery_url = Ansel::getUrlFor('view', array_merge(array('gallery' => $view->parent->id, 'slug' => $view->parent->get('slug'), 'view' => 'Gallery', 'havesearch' => $haveSearch), $date)); } $view->thumb_url = Ansel::getImageUrl($image->id, $thumbstyle, true, $style); $view->option_select = $view->parent->hasPermission($registry->getAuth(), Horde_Perms::DELETE); $view->option_edit = $view->parent->hasPermission($registry->getAuth(), Horde_Perms::EDIT); $view->imgAttributes = !empty($params['image_view_attributes']) ? $params['image_view_attributes'] : array(); $view->option_comments = ($conf['comments']['allow'] == 'all' || $conf['comments']['allow'] == 'authenticated' && $registry->getAuth()) && empty($params['hide_comments']); $view->imgOnClick = !empty($params['image_onclick']) ? str_replace('%i', $image->id, $params['image_onclick']) : ''; $view->imageCaption = $injector->getInstance('Horde_Core_Factory_TextFilter')->filter($image->caption, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO)); if (!empty($params['image_view_title']) && !empty($image->_data[$params['image_view_title']])) { $title = $image->_data[$params['image_view_title']]; } else { $title = $image->filename; } // In-line caption editing if we have Horde_Perms::EDIT if ($view->option_edit) { try { $geometry = $image->getDimensions($thumbstyle); $injector->createInstance('Horde_Core_Factory_Imple')->create('Ansel_Ajax_Imple_EditCaption', array('dataid' => $image->id, 'id' => $image->id . 'caption', 'width' => $geometry['width'])); } catch (Ansel_Exception $e) { } } return $view->render('image'); }
/** * Return a link to an image, suitable for use in an <img/> tag * Takes into account $conf['vfs']['direct'] and other * factors. * * @param string $imageId The id of the image. * @param string $view The view ('screen', 'thumb', 'full', 'mini') * to show. * @param boolean $full Return a path that includes the server name? * @param Ansel_Style $style Use this gallery style * * @return Horde_Url The image path. */ public static function getImageUrl($imageId, $view = 'screen', $full = false, Ansel_Style $style = null) { global $conf; if (empty($imageId)) { return Horde::url((string) Ansel::getErrorImage($view), $full); } // Default to ansel_default if (is_null($style)) { $style = Ansel::getStyleDefinition('ansel_default'); } // Don't load the image if the view exists $viewHash = Ansel_Image::viewExists($imageId, $view, $style); if ($conf['vfs']['src'] != 'php' && $viewHash === false) { // We have to make sure the image exists first, since we won't // be going through img/*.php to auto-create it. try { $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($imageId); } catch (Exception $e) { Horde::log($e, 'ERR'); return Horde::url((string) Ansel::getErrorImage($view), $full); } try { $image->createView($view, $style, $GLOBALS['prefs']->getValue('watermark_auto') && $view == 'screen' ? $GLOBALS['prefs']->getValue('watermark_text', '') : ''); } catch (Ansel_Exception $e) { return Horde::url((string) Ansel::getErrorImage($view), $full); } $viewHash = $image->getViewHash($view, $style) . '/' . $image->getVFSName($view); } // First check for vfs-direct. If we are not using it, pass this off to // the img/*.php files, and check for sendfile support there. if ($conf['vfs']['src'] != 'direct') { $params = array('image' => $imageId); if (!is_null($style)) { $params['t'] = $style->thumbstyle; $params['b'] = $style->background; if ($style->width) { $params['w'] = $style->width; } if ($style->height) { $params['h'] = $style->height; } } return Horde::url('img/' . $view . '.php', $full)->add($params); } // Using vfs-direct $path = substr(str_pad($imageId, 2, 0, STR_PAD_LEFT), -2) . '/' . $viewHash; if ($full && substr($conf['vfs']['path'], 0, 7) != 'http://') { return Horde::url($conf['vfs']['path'] . $path, true, -1); } else { return new Horde_Url($conf['vfs']['path'] . htmlspecialchars($path)); } }
public function testExif() { $params = array('image_id' => 4200, 'image_filename' => 'exif_test.jpg'); $image = new Ansel_Image($params); $exif = $image->getExif(false); }