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

Last change on this file since 2132 was 2132, checked in by rvelices, 17 years ago
  • RSS feed is PWG charset
  • iptc are now converted from iso-8859-1 or utf-8 (automatic detection) to pwg charset
  • remove function get_language_filepath
  • load_language also checks for the default language
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 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          : $Id: functions_metadata.inc.php 2132 2007-10-09 22:43:09Z rvelices $
9// | last update   : $Date: 2007-10-09 22:43:09 +0000 (Tue, 09 Oct 2007) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 2132 $
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  $imginfo = array();
40  if (false == @getimagesize($filename, $imginfo) )
41  {
42    return $result;
43  }
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 ( isset($value[0]) and $value[0] == chr(0))
86  {
87    $value = substr($value, 1);
88  }
89  // remove binary nulls
90  $value = str_replace(chr(0x00), ' ', $value);
91
92  if ( preg_match('/[\x80-\xff]/', $value) )
93  {
94    // apparently mac uses some MacRoman crap encoding. I don't know
95    // how to detect it so a plugin should do the trick.
96    $value = trigger_event('clean_iptc_value', $value);
97    $is_utf8 = seems_utf8($value);
98    $value = convert_charset( $value,
99      $is_utf8 ? 'utf-8' : 'iso-8859-1',
100      get_pwg_charset() );
101  }
102  return $value;
103}
104
105/**
106 * returns informations from EXIF metadata, mapping is done at the beginning
107 * of the function
108 *
109 * @param string $filename
110 * @return array
111 */
112function get_exif_data($filename, $map)
113{
114  $result = array();
115
116  if (!function_exists('read_exif_data'))
117  {
118    die('Exif extension not available, admin should disable exif use');
119  }
120
121  // Read EXIF data
122  if ($exif = @read_exif_data($filename))
123  {
124    foreach ($map as $key => $field)
125    {
126      if (strpos($field, ';') === false)
127      {
128        if (isset($exif[$field]))
129        {
130          $result[$key] = $exif[$field];
131        }
132      }
133      else
134      {
135        $tokens = explode(';', $field);
136        if (isset($exif[$tokens[0]][$tokens[1]]))
137        {
138          $result[$key] = $exif[$tokens[0]][$tokens[1]];
139        }
140      }
141    }
142  }
143
144  return $result;
145}
146?>
Note: See TracBrowser for help on using the repository browser.