source: trunk/include/functions_metadata.inc.php @ 858

Last change on this file since 858 was 858, checked in by plg, 19 years ago
  • modification : less configuration parameters in administration screen. These parameters are move to include/config_default.inc.php.
  • new : ability to add a single picture to caddie from picture.php
  • new : contextual help, only a few pages are available.
  • new : ability to delete users from admin/user_list
  • modification : reorganization of configuration file
  • new : configuration parameter use_exif_mapping
  • improvement : MOD hidemail added to standard
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2005-09-03 16:36:05 +0000 (Sat, 03 Sep 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 858 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28/**
29 * returns informations from IPTC metadata, mapping is done at the beginning
30 * of the function
31 *
32 * @param string $filename
33 * @return array
34 */
35function get_iptc_data($filename, $map)
36{
37  $result = array();
38 
39  // Read IPTC data
40  $iptc = array();
41 
42  $imginfo = array();
43  getimagesize($filename, $imginfo);
44 
45  if (isset($imginfo['APP13']))
46  {
47    $iptc = iptcparse($imginfo['APP13']);
48    if (is_array($iptc))
49    {
50      $rmap = array_flip($map);
51      foreach (array_keys($rmap) as $iptc_key)
52      {
53        if (isset($iptc[$iptc_key][0]))
54        {
55          if ($iptc_key == '2#025')
56          {
57            $value = implode(',',
58                             array_map('clean_iptc_value',$iptc[$iptc_key]));
59          }
60          else
61          {
62            $value = clean_iptc_value($iptc[$iptc_key][0]);
63          }
64
65          foreach (array_keys($map, $iptc_key) as $pwg_key)
66          {
67            $result[$pwg_key] = $value;
68          }
69        }
70      }
71    }
72  }
73  return $result;
74}
75
76/**
77 * return a cleaned IPTC value
78 *
79 * @param string value
80 * @return string
81 */
82function clean_iptc_value($value)
83{
84  // strip leading zeros (weird Kodak Scanner software)
85  while ($value[0] == chr(0))
86  {
87    $value = substr($value, 1);
88  }
89  // remove binary nulls
90  $value = str_replace(chr(0x00), ' ', $value);
91 
92  return $value;
93}
94
95/**
96 * returns informations from EXIF metadata, mapping is done at the beginning
97 * of the function
98 *
99 * @param string $filename
100 * @return array
101 */
102function get_exif_data($filename, $map)
103{
104  $result = array();
105
106  if (!function_exists('read_exif_data'))
107  {
108    die('Exif extension not available, admin should disable exif use');
109  }
110 
111  // Read EXIF data
112  if ($exif = @read_exif_data($filename))
113  {
114    foreach ($map as $key => $field)
115    {
116      if (strpos($field, ';') === false)
117      {
118        if (isset($exif[$field]))
119        {
120          $result[$key] = $exif[$field];
121        }
122      }
123      else
124      {
125        $tokens = explode(';', $field);
126        if (isset($exif[$tokens[0]][$tokens[1]]))
127        {
128          $result[$key] = $exif[$tokens[0]][$tokens[1]];
129        }
130      }
131    }
132  }
133
134  return $result;
135}
136?>
Note: See TracBrowser for help on using the repository browser.