source: branches/2.0/tools/metadata.php @ 21849

Last change on this file since 21849 was 3046, checked in by plg, 16 years ago

Administration: happy new year 2009, all PHP headers updated.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24$filename = 'sample.jpg';
25echo 'Informations are read from '.$filename.'<br /><br /><br />';
26
27/**
28 * return a cleaned IPTC value
29 *
30 * @param string value
31 * @return string
32 */
33function clean_iptc_value($value)
34{
35  // strip leading zeros (weird Kodak Scanner software)
36  while ( isset($value[0]) and $value[0] == chr(0))
37  {
38    $value = substr($value, 1);
39  }
40  // remove binary nulls
41  $value = str_replace(chr(0x00), ' ', $value);
42
43  return $value;
44}
45
46$iptc_result = array();
47$imginfo = array();
48getimagesize($filename, $imginfo);
49if (isset($imginfo['APP13']))
50{
51  $iptc = iptcparse($imginfo['APP13']);
52  if (is_array($iptc))
53  {
54    foreach (array_keys($iptc) as $iptc_key)
55    {
56      if (isset($iptc[$iptc_key][0]))
57      {
58        if ($iptc_key == '2#025')
59        {
60          $value = implode(
61            ',',
62            array_map(
63              'clean_iptc_value',
64              $iptc[$iptc_key]
65              )
66            );
67        }
68        else
69        {
70          $value = clean_iptc_value($iptc[$iptc_key][0]);
71        }
72       
73        $iptc_result[$iptc_key] = $value;
74      }
75    }
76  }
77
78  echo 'IPTC Fields in '.$filename.'<br />';
79  $keys = array_keys($iptc_result);
80  sort($keys);
81  foreach ($keys as $key)
82  {
83    echo '<br />'.$key.' = '.$iptc_result[$key];
84  }
85}
86else
87{
88  echo 'no IPTC information';
89}
90
91echo '<br /><br /><br />';
92echo 'EXIF Fields in '.$filename.'<br />';
93$exif = read_exif_data($filename);
94echo '<pre>';
95print_r($exif);
96echo '</pre>';
97?>
Note: See TracBrowser for help on using the repository browser.