From 066854424a683f14f70f54e3ef1879e77c409369 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Fri, 27 Mar 2009 17:36:14 +0000 Subject: Add a method to create a micro_thumb that is centered vertically in its container (initially used for organize album view) --- core/models/item.php | 55 ++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 10 deletions(-) (limited to 'core') diff --git a/core/models/item.php b/core/models/item.php index 0f7c24fe..528752e8 100644 --- a/core/models/item.php +++ b/core/models/item.php @@ -336,9 +336,52 @@ class Item_Model extends ORM_MPTT { /** * Return an tag for the thumbnail. * @param array $extra_attrs Extra attributes to add to the img tag + * @param int (optional) $max Maximum size of the thumbnail (default: null) * @return string */ public function thumb_tag($extra_attrs=array(), $max=null) { + list ($height, $width) = $this->_adjust_thumb_size($max); + $attrs = array_merge($extra_attrs, + array( + "src" => $this->thumb_url(), + "alt" => $this->title, + "width" => $width, + "height" => $height) + ); + // html::image forces an absolute url which we don't want + return ""; + } + + /** + * Return an tag for a micro thumbnail. Use margins to center within the specified size + * @param array $extra_attrs Extra attributes to add to the img tag + * @param int (optional) $max Maximum size of the thumbnail (default: null) + * @return string + */ + public function micro_thumb_tag($extra_attrs=array(), $max=null) { + list ($height, $width) = $this->_adjust_thumb_size($max); + // The constant is divide by 2 to calcuate the file and 10 to convert to em + $margin_top = ($max - $height) / 20; + $extra_attrs["style"] = "margin-top: {$margin_top}em"; + + $attrs = array_merge($extra_attrs, + array( + "src" => $this->thumb_url(), + "alt" => $this->title, + "title" => $this->title, + "width" => $width, + "height" => $height) + ); + // html::image forces an absolute url which we don't want + return ""; + } + + /** + * Adjust the height based on the input maximum size or zero if not thumbnail + * @param int $max Maximum size of the thumbnail + * @return array + */ + private function _adjust_thumb_size($max) { $width = $this->thumb_width; $height = $this->thumb_height; @@ -358,17 +401,9 @@ class Item_Model extends ORM_MPTT { $width = 0; $height = 0; } - $attrs = array_merge($extra_attrs, - array( - "src" => $this->thumb_url(), - "alt" => $this->title, - "width" => $width, - "height" => $height) - ); - // html::image forces an absolute url which we don't want - return ""; + return array($height, $width); } - + /** * Return an tag for the resize. * @param array $extra_attrs Extra attributes to add to the img tag -- cgit v1.2.3