From 55efc227eaeb2d480ff22837b78f89766b07fe5f Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Sun, 24 Jul 2005 13:55:40 +0200 Subject: first step in Image metadata support This adds a detail page for images, for JPEG files additional metadata from EXIF and IPTC fields is shown darcs-hash:20050724115540-7ad00-926601cd12a990e041943edc616360d8179d6c9f.gz --- inc/template.php | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'inc/template.php') diff --git a/inc/template.php b/inc/template.php index 1ee995b5c..d9b0454f1 100644 --- a/inc/template.php +++ b/inc/template.php @@ -203,6 +203,17 @@ function tpl_link($url,$name,$more=''){ print ">$name"; } +/** + * Prints a link to a WikiPage + * + * Wrapper around html_wikilink + * + * @author Andreas Gohr + */ +function tpl_pagelink($id,$name=NULL){ + print html_wikilink($id,$name); +} + /** * get the parent page * @@ -699,4 +710,71 @@ function tpl_pagetitle($id=null){ print hsc($name); } +/** + * Returns the requested EXIF/IPTC tag from the current image + * + * If $tags is an array all given tags are tried until a + * value is found. If no value is found $alt is returned. + * + * Which texts are known is defined in the functions _exifTagNames + * and _iptcTagNames() in inc/jpeg.php (You need to prepend IPTC + * to the names of the latter one) + * + * Only allowed in: detail.php + * + * @author Andreas Gohr + */ +function tpl_img_getTag($tags,$alt=''){ + // Init Exif Reader + global $SRC; + static $meta = null; + if(is_null($meta)) $meta = new JpegMeta($SRC); + if($meta === false) return $alt; + $info = $meta->getField($tags); + if($info == false) return $alt; + return $info; +} + +/** + * Prints the image with a link to the full sized version + * + * Only allowed in: detail.php + */ +function tpl_img($maxwidth=900,$maxheight=700){ + global $IMG; + $w = tpl_img_getTag('File.Width'); + $h = tpl_img_getTag('File.Height'); + + //resize to given max values + $ratio = 0; + if($w > $h){ + if($w > $maxwidth){ + $ratio = $maxwidth/$w; + }elseif($h > $maxheight){ + $ratio = $maxheight/$h; + } + }else{ + if($h > $maxheight){ + $ratio = $maxheight/$h; + }elseif($w > $maxwidth){ + $ratio = $maxwidth/$w; + } + } + if($ratio){ + $w = floor($ratio*$w); + $h = floor($ratio*$h); + } + + //FIXME add alt attribute, classes + + $url=DOKU_BASE.'lib/exe/fetch.php?cache='.urlencode($_REQUEST['cache']). + '&media='.urlencode($IMG); + + $alt=tpl_img_getTag('Simple.Title'); + + print ''; + print ''; + print ''; +} + //Setup VIM: ex: et ts=2 enc=utf-8 : -- cgit v1.2.3