diff options
author | z0rglub <z0rglub@piwigo.org> | 2004-08-25 21:09:09 +0000 |
---|---|---|
committer | z0rglub <z0rglub@piwigo.org> | 2004-08-25 21:09:09 +0000 |
commit | d8494248fc3df1ac9b688fd5b250de60a50361b2 (patch) | |
tree | 209664043b3f2014be7acd492ba5a3b690c11883 | |
parent | 593574214c8dcbd9fa5bb79060d9bbbc81ffd1fc (diff) |
"show metadata" feature added : you can ask to show metadata (EXIF and IPTC)
on picture.php page. Metadata read functions were moved from
admin/include/functions_metadata.php to include/functions_metadata.inc.php
git-svn-id: http://piwigo.org/svn/trunk@493 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r-- | admin/configuration.php | 8 | ||||
-rw-r--r-- | admin/include/functions_metadata.php | 74 | ||||
-rw-r--r-- | include/config.inc.php | 30 | ||||
-rw-r--r-- | include/functions_metadata.inc.php | 73 | ||||
-rw-r--r-- | install/config.sql | 2 | ||||
-rw-r--r-- | language/en_UK.iso-8859-1/admin.lang.php | 4 | ||||
-rw-r--r-- | language/en_UK.iso-8859-1/common.lang.php | 3 | ||||
-rw-r--r-- | picture.php | 137 | ||||
-rw-r--r-- | template/default/admin/configuration.tpl | 20 | ||||
-rw-r--r-- | template/default/picture.tpl | 24 | ||||
-rw-r--r-- | tools/metadata.php | 74 |
11 files changed, 392 insertions, 57 deletions
diff --git a/admin/configuration.php b/admin/configuration.php index 1d8356444..369e0cdda 100644 --- a/admin/configuration.php +++ b/admin/configuration.php @@ -210,6 +210,8 @@ $upload = ($conf['upload_available']=='true')?'UPLOAD_YES':'UPLOAD_NO'; $cookie = ($conf['authorize_cookies']=='true')?'COOKIE_YES':'COOKIE_NO'; $use_exif = ($conf['use_exif']=='true')?'USE_EXIF_YES':'USE_EXIF_NO'; $use_iptc = ($conf['use_iptc']=='true')?'USE_IPTC_YES':'USE_IPTC_NO'; +$show_exif = ($conf['show_exif']=='true')?'SHOW_EXIF_YES':'SHOW_EXIF_NO'; +$show_iptc = ($conf['show_iptc']=='true')?'SHOW_IPTC_YES':'SHOW_IPTC_NO'; //----------------------------------------------------- template initialization $template->set_filenames( array('config'=>'admin/configuration.tpl') ); @@ -244,6 +246,8 @@ $template->assign_vars(array( $cookie=>'checked="checked"', $use_exif=>'checked="checked"', $use_iptc=>'checked="checked"', + $show_exif=>'checked="checked"', + $show_iptc=>'checked="checked"', 'L_CONFIRM'=>$lang['conf_confirmation'], 'L_CONF_GENERAL'=>$lang['conf_general_title'], @@ -313,6 +317,10 @@ $template->assign_vars(array( 'L_USE_EXIF_INFO'=>$lang['conf_use_exif_info'], 'L_USE_IPTC'=>$lang['conf_use_iptc'], 'L_USE_IPTC_INFO'=>$lang['conf_use_iptc_info'], + 'L_SHOW_EXIF'=>$lang['conf_show_exif'], + 'L_SHOW_EXIF_INFO'=>$lang['conf_show_exif_info'], + 'L_SHOW_IPTC'=>$lang['conf_show_iptc'], + 'L_SHOW_IPTC_INFO'=>$lang['conf_show_iptc_info'], 'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?page=configuration') )); diff --git a/admin/include/functions_metadata.php b/admin/include/functions_metadata.php index 9a7d45193..14d5a0d16 100644 --- a/admin/include/functions_metadata.php +++ b/admin/include/functions_metadata.php @@ -25,17 +25,10 @@ // | USA. | // +-----------------------------------------------------------------------+ -/** - * returns informations from IPTC metadata, mapping is done at the beginning - * of the function - * - * @param string $filename - * @return array - */ -function get_iptc_data($filename) +include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php'); + +function get_sync_iptc_data($file) { - global $getimagesize_time; - $map = array( 'keywords' => '2#025', 'date_creation' => '2#055', @@ -45,61 +38,25 @@ function get_iptc_data($filename) ); $datefields = array('date_creation', 'date_available'); - $result = array(); - - // Read IPTC data - $iptc = array(); - - $start = get_moment(); - getimagesize($filename, &$imginfo); - $getimagesize_time+= get_moment() - $start; - - if (is_array($imginfo) and isset($imginfo['APP13'])) + $iptc = get_iptc_data($file, $map); + + foreach ($iptc as $pwg_key => $value) { - $iptc = iptcparse($imginfo['APP13']); - if (is_array($iptc)) + if (in_array($pwg_key, $datefields)) { - $rmap = array_flip($map); - foreach (array_keys($rmap) as $iptc_key) + if ( preg_match('/(\d{4})(\d{2})(\d{2})/', $value, $matches)) { - if (isset($iptc[$iptc_key][0]) and $value = $iptc[$iptc_key][0]) - { - // strip leading zeros (weird Kodak Scanner software) - while ($value[0] == chr(0)) - { - $value = substr($value, 1); - } - // remove binary nulls - $value = str_replace(chr(0x00), ' ', $value); - - foreach (array_keys($map, $iptc_key) as $pwg_key) - { - if (in_array($pwg_key, $datefields)) - { - if ( preg_match('/(\d{4})(\d{2})(\d{2})/', $value, $matches)) - { - $value = $matches[1].'-'.$matches[2].'-'.$matches[3]; - } - else - { - continue; - } - } - $result[$pwg_key] = $value; - } - } + $iptc[$pwg_key] = $matches[1].'-'.$matches[2].'-'.$matches[3]; } } } - return $result; + + return $iptc; } function update_metadata($files) { global $conf; - -// $conf['use_iptc'] = true; -// $conf['use_exif'] = true; $inserts = array(); @@ -132,10 +89,13 @@ function update_metadata($files) if ($conf['use_iptc']) { - $iptc = get_iptc_data($file); - foreach (array_keys($iptc) as $key) + $iptc = get_sync_iptc_data($file); + if (count($iptc) > 0) { - $insert[$key] = "'".addslashes($iptc[$key])."'"; + foreach (array_keys($iptc) as $key) + { + $insert[$key] = "'".addslashes($iptc[$key])."'"; + } } } diff --git a/include/config.inc.php b/include/config.inc.php index 12e33c573..2c3fdae81 100644 --- a/include/config.inc.php +++ b/include/config.inc.php @@ -58,4 +58,34 @@ $conf['top_number'] = 10; $conf['anti-flood_time'] = 60; // seconds between 2 comments : 0 to disable $conf['max_LOV_categories'] = 50; +// $conf['show_iptc_mapping'] is used for showing IPTC metadata on +// picture.php page. For each key of the array, you need to have the same +// key in the $lang array. For example, if my first key is 'iptc_keywords' +// (associated to '2#025') then you need to have $lang['iptc_keywords'] set +// in language/$user['language']/common.lang.php. If you don't have the lang +// var set, the key will be simply displayed +// +// To know how to associated iptc_field with their meaning, use +// tools/metadata.php +$conf['show_iptc_mapping'] = array( + 'iptc_keywords' => '2#025', + 'iptc_caption_writer' => '2#122', + 'iptc_byline_title' => '2#085', + 'iptc_caption' => '2#120' + ); + +// in EXIF fields, you can choose to display fields in sub-arrays, for +// example ['COMPUTED']['ApertureFNumber']. for this, add +// 'COMPUTED;ApertureFNumber' in $conf['show_exif_fields'] +// +// The key displayed in picture.php will be $lang['exif_field_Make'] for +// example and if it exists. For compound fields, only take into account the +// last part : for key 'COMPUTED;ApertureFNumber', you need +// $lang['exif_field_ApertureFNumber'] +$conf['show_exif_fields'] = array('Make', + 'Model', + 'DateTime', + 'COMPUTED;ApertureFNumber'); +// for PHP version newer than 4.1.2 : +// $conf['show_exif_fields'] = array('CameraMake','CameraModel','DateTime'); ?> diff --git a/include/functions_metadata.inc.php b/include/functions_metadata.inc.php new file mode 100644 index 000000000..e2b7333d5 --- /dev/null +++ b/include/functions_metadata.inc.php @@ -0,0 +1,73 @@ +<?php +// +-----------------------------------------------------------------------+ +// | functions_metadata.inc.php | +// +-----------------------------------------------------------------------+ +// | application : PhpWebGallery <http://phpwebgallery.net> | +// | branch : BSF (Best So Far) | +// +-----------------------------------------------------------------------+ +// | file : $RCSfile$ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Revision$ +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +/** + * returns informations from IPTC metadata, mapping is done at the beginning + * of the function + * + * @param string $filename + * @return array + */ +function get_iptc_data($filename, $map) +{ + $result = array(); + + // Read IPTC data + $iptc = array(); + + $imginfo = array(); + getimagesize($filename, $imginfo); + + if (isset($imginfo['APP13'])) + { + $iptc = iptcparse($imginfo['APP13']); + if (is_array($iptc)) + { + $rmap = array_flip($map); + foreach (array_keys($rmap) as $iptc_key) + { + if (isset($iptc[$iptc_key][0]) and $value = $iptc[$iptc_key][0]) + { + // strip leading zeros (weird Kodak Scanner software) + while ($value[0] == chr(0)) + { + $value = substr($value, 1); + } + // remove binary nulls + $value = str_replace(chr(0x00), ' ', $value); + + foreach (array_keys($map, $iptc_key) as $pwg_key) + { + $result[$pwg_key] = $value; + } + } + } + } + } + return $result; +} +?>
\ No newline at end of file diff --git a/install/config.sql b/install/config.sql index 987c8a4a5..3ef928a4f 100644 --- a/install/config.sql +++ b/install/config.sql @@ -29,3 +29,5 @@ INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('auto_expand','fa INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('show_nb_comments','true','Show the number of comments under the thumbnails'); INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('use_iptc','false','Use IPTC data during database synchronization with files metadata'); INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('use_exif','true','Use EXIF data during database synchronization with files metadata'); +INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('show_iptc','false','Show IPTC metadata on picture.php if asked by user'); +INSERT INTO phpwebgallery_config (param,value,comment) VALUES ('show_exif','true','Show EXIF metadata on picture.php if asked by user'); diff --git a/language/en_UK.iso-8859-1/admin.lang.php b/language/en_UK.iso-8859-1/admin.lang.php index 5741b5d34..48f3157b2 100644 --- a/language/en_UK.iso-8859-1/admin.lang.php +++ b/language/en_UK.iso-8859-1/admin.lang.php @@ -159,6 +159,10 @@ $lang['conf_use_exif'] = 'Use EXIF'; $lang['conf_use_exif_info'] = 'Use EXIF data during metadata synchronization into PhpWebGallery database'; $lang['conf_use_iptc'] = 'Use IPTC'; $lang['conf_use_iptc_info'] = 'Use IPTC data during metadata synchronization into PhpWebGallery database'; +$lang['conf_show_exif'] = 'Show EXIF'; +$lang['conf_show_exif_info'] = 'Give the possibility to show EXIF metadata on visualisation page. See include/config.inc.php for available EXIF fields'; +$lang['conf_show_iptc'] = 'Show IPTC'; +$lang['conf_show_iptc_info'] = 'Give the possibility to show IPTC metadata on visualisation page. See include/config.inc.php for available IPTC fields'; //FAQ $lang['help_images_title'] = 'Adding pictures'; diff --git a/language/en_UK.iso-8859-1/common.lang.php b/language/en_UK.iso-8859-1/common.lang.php index 9feac861f..c1490b041 100644 --- a/language/en_UK.iso-8859-1/common.lang.php +++ b/language/en_UK.iso-8859-1/common.lang.php @@ -279,4 +279,7 @@ $lang['search_author'] = 'author'; $lang['search_date_available'] = 'availability date'; $lang['search_date_creation'] = 'creation date'; $lang['search_one_clause_at_least'] = 'search at least on one search clause'; + +$lang['picture_show_metadata'] = 'Show file metadata ?'; +$lang['picture_hide_metadata'] = 'Hide file metadata'; ?>
\ No newline at end of file diff --git a/picture.php b/picture.php index d08928679..78c80d884 100644 --- a/picture.php +++ b/picture.php @@ -197,6 +197,10 @@ foreach (array('prev', 'current', 'next') as $i) { $picture[$i]['url'].= '&search='.$_GET['search']; } + if (isset($_GET['show_metadata'])) + { + $picture[$i]['url'].= '&show_metadata=1'; + } } $url_home = PHPWG_ROOT_PATH.'category.php?cat='.$page['cat'].'&'; @@ -405,6 +409,8 @@ $template->assign_vars(array( 'L_COMMENT' =>$lang['comment'], 'L_DOWNLOAD' => $lang['download'], 'L_DOWNLOAD_HINT' => $lang['download_hint'], + 'L_PICTURE_SHOW_METADATA' => $lang['picture_show_metadata'], + 'L_PICTURE_HIDE_METADATA' => $lang['picture_hide_metadata'], 'T_DEL_IMG' =>PHPWG_ROOT_PATH.'template/'.$user['template'].'/theme/delete.gif', @@ -570,7 +576,138 @@ $template->assign_block_vars('info_line', array( 'INFO'=>$lang['visited'], 'VALUE'=>$picture['current']['hit'].' '.$lang['times'] )); +//-------------------------------------------------------------------- metadata +if ($conf['show_exif'] or $conf['show_iptc']) +{ + $metadata_showable = true; +} +else +{ + $metadata_showable = false; +} + +if ($metadata_showable and !isset($_GET['show_metadata'])) +{ + $url = PHPWG_ROOT_PATH.'picture.php?'.$_SERVER['QUERY_STRING']; + $url.= '&show_metadata=1'; + $template->assign_block_vars('show_metadata', array('URL' => $url)); +} +if ($metadata_showable and isset($_GET['show_metadata'])) +{ + $url = PHPWG_ROOT_PATH.'picture.php'; + + $str = $_SERVER['QUERY_STRING']; + parse_str($str, $get_vars); + $is_first = true; + foreach ($get_vars as $key => $value) + { + if ($key != 'show_metadata') + { + if ($is_first) + { + $url.= '?'; + $is_first = false; + } + else + { + $url.= '&'; + } + $url.= $key.'='.$value; + } + } + + $template->assign_block_vars('hide_metadata', array('URL' => $url)); + + include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php'); + + $template->assign_block_vars('metadata', array()); + + if ($conf['show_exif']) + { + if ($exif = @read_exif_data($picture['current']['src'])) + { + $template->assign_block_vars( + 'metadata.headline', + array('TITLE' => 'EXIF Metadata') + ); + + foreach ($conf['show_exif_fields'] as $field) + { + if (strpos($field, ';') === false) + { + if (isset($exif[$field])) + { + $key = $field; + if (isset($lang['exif_field_'.$field])) + { + $key = $lang['exif_field_'.$field]; + } + + $template->assign_block_vars( + 'metadata.line', + array( + 'KEY' => $key, + 'VALUE' => $exif[$field] + ) + ); + } + } + else + { + $tokens = explode(';', $field); + if (isset($exif[$tokens[0]][$tokens[1]])) + { + $key = $tokens[1]; + if (isset($lang['exif_field_'.$tokens[1]])) + { + $key = $lang['exif_field_'.$tokens[1]]; + } + + $template->assign_block_vars( + 'metadata.line', + array( + 'KEY' => $key, + 'VALUE' => $exif[$tokens[0]][$tokens[1]] + ) + ); + } + } + } + } + } + + if ($conf['show_iptc']) + { + $iptc = get_iptc_data($picture['current']['src'], + $conf['show_iptc_mapping']); + + if (count($iptc) > 0) + { + $template->assign_block_vars( + 'metadata.headline', + array('TITLE' => 'IPTC Metadata') + ); + } + + foreach ($iptc as $field => $value) + { + $key = $field; + if (isset($lang[$field])) + { + $key = $lang[$field]; + } + + $template->assign_block_vars( + 'metadata.line', + array( + 'KEY' => $key, + 'VALUE' => $value + ) + ); + } + } +} //------------------------------------------------------- favorite manipulation if ( !$user['is_the_guest'] ) { diff --git a/template/default/admin/configuration.tpl b/template/default/admin/configuration.tpl index b2eb8f22b..d1a528b6d 100644 --- a/template/default/admin/configuration.tpl +++ b/template/default/admin/configuration.tpl @@ -197,6 +197,26 @@ <input type="radio" class="radio" name="use_iptc" value="false" {USE_IPTC_NO} />{L_NO} </td> </tr> + <tr> + <td> + <strong>{L_SHOW_EXIF} :</strong> + <br /><span class="small">{L_SHOW_EXIF_INFO}</span> + </td> + <td class="row1"> + <input type="radio" class="radio" name="show_exif" value="true" {SHOW_EXIF_YES} />{L_YES} + <input type="radio" class="radio" name="show_exif" value="false" {SHOW_EXIF_NO} />{L_NO} + </td> + </tr> + <tr> + <td> + <strong>{L_SHOW_IPTC} :</strong> + <br /><span class="small">{L_SHOW_IPTC_INFO}</span> + </td> + <td class="row1"> + <input type="radio" class="radio" name="show_iptc" value="true" {SHOW_IPTC_YES} />{L_YES} + <input type="radio" class="radio" name="show_iptc" value="false" {SHOW_IPTC_NO} />{L_NO} + </td> + </tr> <!-- BEGIN remote_sites --> <tr> <th colspan="2" align="center">{#remote_site}</th> diff --git a/template/default/picture.tpl b/template/default/picture.tpl index ea301a24e..58d445ced 100644 --- a/template/default/picture.tpl +++ b/template/default/picture.tpl @@ -69,6 +69,30 @@ </a> </div> <!-- END favorite --> + + <!-- BEGIN show_metadata --> + [ <a href="{show_metadata.URL}">{L_PICTURE_SHOW_METADATA}</a> ] + <!-- END show_metadata --> + + <!-- BEGIN hide_metadata --> + [ <a href="{hide_metadata.URL}">{L_PICTURE_HIDE_METADATA}</a> ] + <!-- END hide_metadata --> + + <!-- BEGIN metadata --> + <table class="metadata"> + <!-- BEGIN headline --> + <tr> + <th colspan="2">{metadata.headline.TITLE}</th> + </tr> + <!-- END headline --> + <!-- BEGIN line --> + <tr> + <td>{metadata.line.KEY}</td> + <td>{metadata.line.VALUE}</td> + </tr> + <!-- END line --> + </table> + <!-- END metadata --> <!-- BEGIN modification --> <div class="menu" style="text-align:center;margin:5px;"> [ <a href="{U_ADMIN}">{L_ADMIN}</a> ] diff --git a/tools/metadata.php b/tools/metadata.php new file mode 100644 index 000000000..082d246cf --- /dev/null +++ b/tools/metadata.php @@ -0,0 +1,74 @@ +<?php +// +-----------------------------------------------------------------------+ +// | metadata.php | +// +-----------------------------------------------------------------------+ +// | application : PhpWebGallery <http://phpwebgallery.net> | +// | branch : BSF (Best So Far) | +// +-----------------------------------------------------------------------+ +// | file : $RCSfile$ +// | last update : $Date$ +// | last modifier : $Author$ +// | revision : $Revision$ +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +$filename = 'sample.jpg'; +echo 'Informations are read from '.$filename.'<br /><br /><br />'; + +$iptc_result = array(); +$imginfo = array(); +getimagesize($filename, $imginfo); +if (isset($imginfo['APP13'])) +{ + $iptc = iptcparse($imginfo['APP13']); + if (is_array($iptc)) + { + foreach (array_keys($iptc) as $iptc_key) + { + if (isset($iptc[$iptc_key][0]) and $value = $iptc[$iptc_key][0]) + { + // strip leading zeros (weird Kodak Scanner software) + while ($value[0] == chr(0)) + { + $value = substr($value, 1); + } + // remove binary nulls + $value = str_replace(chr(0x00), ' ', $value); + } + $iptc_result[$iptc_key] = $value; + } + } + + echo 'IPTC Fields in '.$filename.'<br />'; + $keys = array_keys($iptc_result); + sort($keys); + foreach ($keys as $key) + { + echo '<br />'.$key.' = '.$iptc_result[$key]; + } +} +else +{ + echo 'no IPTC information'; +} + +echo '<br /><br /><br />'; +echo 'EXIF Fields in '.$filename.'<br />'; +$exif = read_exif_data($filename); +echo '<pre>'; +print_r($exif); +echo '</pre>'; +?>
\ No newline at end of file |