source: trunk/tools/metadata.php @ 1757

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

merge -r1221:1222 from branch 1.6 to trunk (bug 339)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 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: 2006-04-20 21:13:47 +0000 (Thu, 20 Apr 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1223 $
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$filename = 'sample.jpg';
29echo 'Informations are read from '.$filename.'<br /><br /><br />';
30
31/**
32 * return a cleaned IPTC value
33 *
34 * @param string value
35 * @return string
36 */
37function clean_iptc_value($value)
38{
39  // strip leading zeros (weird Kodak Scanner software)
40  while ( isset($value[0]) and $value[0] == chr(0))
41  {
42    $value = substr($value, 1);
43  }
44  // remove binary nulls
45  $value = str_replace(chr(0x00), ' ', $value);
46
47  return $value;
48}
49
50$iptc_result = array();
51$imginfo = array();
52getimagesize($filename, $imginfo);
53if (isset($imginfo['APP13']))
54{
55  $iptc = iptcparse($imginfo['APP13']);
56  if (is_array($iptc))
57  {
58    foreach (array_keys($iptc) as $iptc_key)
59    {
60      if (isset($iptc[$iptc_key][0]))
61      {
62        if ($iptc_key == '2#025')
63        {
64          $value = implode(
65            ',',
66            array_map(
67              'clean_iptc_value',
68              $iptc[$iptc_key]
69              )
70            );
71        }
72        else
73        {
74          $value = clean_iptc_value($iptc[$iptc_key][0]);
75        }
76       
77        $iptc_result[$iptc_key] = $value;
78      }
79    }
80  }
81
82  echo 'IPTC Fields in '.$filename.'<br />';
83  $keys = array_keys($iptc_result);
84  sort($keys);
85  foreach ($keys as $key)
86  {
87    echo '<br />'.$key.' = '.$iptc_result[$key];
88  }
89}
90else
91{
92  echo 'no IPTC information';
93}
94
95echo '<br /><br /><br />';
96echo 'EXIF Fields in '.$filename.'<br />';
97$exif = read_exif_data($filename);
98echo '<pre>';
99print_r($exif);
100echo '</pre>';
101?>
Note: See TracBrowser for help on using the repository browser.