summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2005-07-31 13:50:30 +0200
committerAndreas Gohr <andi@splitbrain.org>2005-07-31 13:50:30 +0200
commit23a34783631a54703aa67aa0de81c404c59ef4ef (patch)
tree42bea8efb0c012a2e89e1678ccdd8663b70497f0
parent4b15e09d7fd735b5df41e47b6e324e0bc44fa872 (diff)
downloadrpg-23a34783631a54703aa67aa0de81c404c59ef4ef.tar.gz
rpg-23a34783631a54703aa67aa0de81c404c59ef4ef.tar.bz2
optimized Image metadata handling
darcs-hash:20050731115030-7ad00-2a1a423985864f0daae57545c2f3945abfc10257.gz
-rw-r--r--inc/JpegMeta.php39
-rw-r--r--inc/search.php3
-rw-r--r--inc/template.php46
3 files changed, 70 insertions, 18 deletions
diff --git a/inc/JpegMeta.php b/inc/JpegMeta.php
index 656e98625..b9f0908d4 100644
--- a/inc/JpegMeta.php
+++ b/inc/JpegMeta.php
@@ -328,6 +328,36 @@ class JpegMeta
}
/**
+ * Calculates the multiplier needed to resize the image to the given
+ * dimensions
+ *
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
+ function getResizeRatio($maxwidth,$maxheight=0){
+ if(!$maxheight) $maxheight = $maxwidth;
+
+ $w = $this->getField('File.Width');
+ $h = $this->getField('File.Height');
+
+ $ratio = 1;
+ 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;
+ }
+ }
+ return $ratio;
+ }
+
+
+ /**
* Set an IPTC field
*
* @author Sebastian Delmont <sdelmont@zonageek.com>
@@ -1090,12 +1120,18 @@ class JpegMeta
return true;
}
- /*************************************************************/
+ /**
+ * Gets basic info from the file - should work with non-JPEGs
+ *
+ * @author Sebastian Delmont <sdelmont@zonageek.com>
+ * @author Andreas Gohr <andi@splitbrain.org>
+ */
function _parseFileInfo()
{
if (file_exists($this->_fileName)) {
$this->_info['file'] = array();
$this->_info['file']['Name'] = basename($this->_fileName);
+ $this->_info['file']['Path'] = realpath($this->_fileName);
$this->_info['file']['Size'] = filesize($this->_fileName);
if ($this->_info['file']['Size'] < 1024) {
$this->_info['file']['NiceSize'] = $this->_info['file']['Size'] . 'B';
@@ -1111,7 +1147,6 @@ class JpegMeta
}
$this->_info['file']['UnixTime'] = filemtime($this->_fileName);
- // Andreas Gohr <andi@splitbrain.org>
// get image size directly from file
$size = getimagesize($this->_fileName);
$this->_info['file']['Width'] = $size[0];
diff --git a/inc/search.php b/inc/search.php
index d949dc6de..3604db15e 100644
--- a/inc/search.php
+++ b/inc/search.php
@@ -174,7 +174,8 @@ function search_media(&$data,$base,$file,$type,$lvl,$opts){
$info['size'] = filesize($base.'/'.$file);
if(preg_match("/\.(jpe?g|gif|png)$/",$file)){
$info['isimg'] = true;
- $info['info'] = getimagesize($base.'/'.$file);
+ require_once(DOKU_INC.'inc/JpegMeta.php');
+ $info['meta'] = new JpegMeta($base.'/'.$file);
}else{
$info['isimg'] = false;
}
diff --git a/inc/template.php b/inc/template.php
index bbbf5bb6b..23123b452 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -629,30 +629,46 @@ function tpl_mediafilelist(){
}
if($item['isimg']){
- $w = $item['info'][0];
- $h = $item['info'][1];
+ $w = $item['meta']->getField('File.Width');
+ $h = $item['meta']->getField('File.Height');
ptln('('.$w.'&#215;'.$h.' '.filesize_h($item['size']).')',6);
ptln($del.'<br />',6);
ptln('<div class="meta">',6);
- ptln('<a href="javascript:mediaSelect(\''.$item['id'].'\')">');
+
+ //build thumbnail
+ print '<a href="javascript:mediaSelect(\''.$item['id'].'\')">';
- if($w>120){
- print '<img src="'.DOKU_BASE.'lib/exe/fetch.php?w=120&amp;media='.urlencode($item['id']).'" width="120" class="thumb" />';
- }else{
- print '<img src="'.DOKU_BASE.'lib/exe/fetch.php?media='.urlencode($item['id']).'" width="'.$w.'" height="'.$h.'" class="thumb" />';
+ if($w>120 || $h>120){
+ $ratio = $item['meta']->getResizeRatio(120);
+ $w = floor($w * $ratio);
+ $h = floor($h * $ratio);
}
+
+ $p = array();
+ $p['w'] = $w;
+ $p['h'] = $h;
+ $p['media'] = $item['id'];
+ $src = DOKU_BASE.'lib/exe/fetch.php?'.buildURLParams($p);
+
+ $p = array();
+ $p['width'] = $w;
+ $p['height'] = $h;
+ $p['alt'] = $item['id'];
+ $p['class'] = 'thumb';
+ $att = buildAttributes($p);
+
+ print '<img src="'.$src.'" '.$att.' />';
print '</a>';
//read EXIF/IPTC data
- $meta = new JpegMeta(mediaFN($item['id']));
- $t = $meta->getField('IPTC.Headline');
+ $t = $item['meta']->getField('IPTC.Headline');
if($t) print '<b>'.$t.'</b><br />';
- $t = $meta->getField(array('IPTC.Caption','EXIF.UserComment','EXIF.TIFFImageDescription','EXIF.TIFFUserComment'));
+ $t = $item['meta']->getField(array('IPTC.Caption','EXIF.UserComment','EXIF.TIFFImageDescription','EXIF.TIFFUserComment'));
if($t) print $t.'<br />';
- $t = $meta->getField(array('IPTC.Keywords','IPTC.Category'));
+ $t = $item['meta']->getField(array('IPTC.Keywords','IPTC.Category'));
if($t) print '<i>'.$t.'</i><br />';
ptln('</div>',6);
@@ -781,15 +797,15 @@ function tpl_img($maxwidth=900,$maxheight=700){
$h = tpl_img_getTag('File.Height');
//resize to given max values
- $ratio = 0;
- if($w > $h){
- if($w > $maxwidth){
+ $ratio = 1;
+ if($w >= $h){
+ if($w >= $maxwidth){
$ratio = $maxwidth/$w;
}elseif($h > $maxheight){
$ratio = $maxheight/$h;
}
}else{
- if($h > $maxheight){
+ if($h >= $maxheight){
$ratio = $maxheight/$h;
}elseif($w > $maxwidth){
$ratio = $maxwidth/$w;