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

Last change on this file since 675 was 675, checked in by plg, 19 years ago

all headers adapted to new year 2005, happy new year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 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-01-07 23:10:51 +0000 (Fri, 07 Jan 2005) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 675 $
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?>
Note: See TracBrowser for help on using the repository browser.