6 |
jpm |
1 |
<?php
|
|
|
2 |
/*vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
3 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
4 |
// | PHP version 5.1 |
|
|
|
5 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
6 |
// | Copyright (C) 1999-2006 Tela Botanica (accueil@tela-botanica.org) |
|
|
|
7 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
8 |
// | This file is part of v2.pierredupontdugard.com. |
|
|
|
9 |
// | |
|
|
|
10 |
// | v2.pierredupontdugard.com is free software; you can redistribute it and/or modify |
|
|
|
11 |
// | it under the terms of the GNU General Public License as published by |
|
|
|
12 |
// | the Free Software Foundation; either version 2 of the License, or |
|
|
|
13 |
// | (at your option) any later version. |
|
|
|
14 |
// | |
|
|
|
15 |
// | v2.pierredupontdugard.com is distributed in the hope that it will be useful, |
|
|
|
16 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
17 |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
18 |
// | GNU General Public License for more details. |
|
|
|
19 |
// | |
|
|
|
20 |
// | You should have received a copy of the GNU General Public License |
|
|
|
21 |
// | along with Foobar; if not, write to the Free Software |
|
|
|
22 |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
|
23 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
24 |
// CVS : $Id$
|
|
|
25 |
/**
|
|
|
26 |
* v2.pierredupontdugard.com - metadonnees.fonct.php
|
|
|
27 |
*
|
|
|
28 |
* Description :
|
|
|
29 |
*
|
|
|
30 |
*@package v2.pierredupontdugard.com
|
|
|
31 |
//Auteur original :
|
|
|
32 |
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
33 |
//Autres auteurs :
|
|
|
34 |
*@author Aucun
|
|
|
35 |
*@copyright Tela-Botanica 1999-2008
|
|
|
36 |
*@version $Revision$ $Date$
|
|
|
37 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
38 |
*/
|
|
|
39 |
|
|
|
40 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
41 |
// | ENTETE du PROGRAMME |
|
|
|
42 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
46 |
// | CORPS du PROGRAMME |
|
|
|
47 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* returns informations from IPTC metadata, mapping is done at the beginning
|
|
|
51 |
* of the function
|
|
|
52 |
*
|
|
|
53 |
* @param string $filename
|
|
|
54 |
* @return array
|
|
|
55 |
*/
|
|
|
56 |
function get_iptc_data($filename, $map)
|
|
|
57 |
{
|
|
|
58 |
$result = array();
|
|
|
59 |
|
|
|
60 |
$imginfo = array();
|
|
|
61 |
if (false == @getimagesize($filename, $imginfo) ) {
|
|
|
62 |
return $result;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
if (isset($imginfo['APP13'])) {
|
|
|
66 |
$iptc = iptcparse($imginfo['APP13']);
|
|
|
67 |
if (is_array($iptc)) {
|
|
|
68 |
$rmap = array_flip($map);
|
|
|
69 |
foreach (array_keys($rmap) as $iptc_key) {
|
|
|
70 |
if (isset($iptc[$iptc_key][0])) {
|
|
|
71 |
if ($iptc_key == '2#025') {
|
|
|
72 |
$value = implode(',', array_map('clean_iptc_value',$iptc[$iptc_key]));
|
|
|
73 |
} else {
|
|
|
74 |
$value = clean_iptc_value($iptc[$iptc_key][0]);
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
foreach (array_keys($map, $iptc_key) as $pwg_key) {
|
|
|
78 |
$result[$pwg_key] = $value;
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
}
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
return $result;
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
/**
|
|
|
88 |
* return a cleaned IPTC value
|
|
|
89 |
*
|
|
|
90 |
* @param string value
|
|
|
91 |
* @return string
|
|
|
92 |
*/
|
|
|
93 |
function clean_iptc_value($value)
|
|
|
94 |
{
|
|
|
95 |
// strip leading zeros (weird Kodak Scanner software)
|
|
|
96 |
while ( isset($value[0]) and $value[0] == chr(0)) {
|
|
|
97 |
$value = substr($value, 1);
|
|
|
98 |
}
|
|
|
99 |
// remove binary nulls
|
|
|
100 |
$value = str_replace(chr(0x00), ' ', $value);
|
|
|
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 |
*/
|
|
|
112 |
function get_exif_data($filename, $map)
|
|
|
113 |
{
|
|
|
114 |
$result = array();
|
|
|
115 |
|
|
|
116 |
if (!function_exists('read_exif_data')) {
|
|
|
117 |
die('Exif extension not available, admin should disable exif use');
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
// Read EXIF data
|
|
|
121 |
if ($exif = @read_exif_data($filename)) {
|
|
|
122 |
foreach ($map as $key => $field) {
|
|
|
123 |
if (strpos($field, ';') === false) {
|
|
|
124 |
if (isset($exif[$field])) {
|
|
|
125 |
if ($field == 'UserComment') {
|
|
|
126 |
$result[$key] = substr($exif[$field], 8);
|
|
|
127 |
// Récupère l'encodage du champ et supprime les caractères NULL de complétion
|
|
|
128 |
$result[$key.'_encodage'] = substr($exif[$field], 0, strpos($exif[$field] , chr(0)));
|
|
|
129 |
} else {
|
|
|
130 |
$result[$key] = $exif[$field];
|
|
|
131 |
}
|
|
|
132 |
}
|
|
|
133 |
} else {
|
|
|
134 |
$tokens = explode(';', $field);
|
|
|
135 |
if (isset($exif[$tokens[0]][$tokens[1]])) {
|
|
|
136 |
$result[$key] = $exif[$tokens[0]][$tokens[1]];
|
|
|
137 |
}
|
|
|
138 |
}
|
|
|
139 |
}
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
return $result;
|
|
|
143 |
}
|
|
|
144 |
|
|
|
145 |
/* +--Fin du code ----------------------------------------------------------------------------------------+
|
|
|
146 |
*
|
|
|
147 |
* $Log$
|
|
|
148 |
*
|
|
|
149 |
* +-- Fin du code ----------------------------------------------------------------------------------------+
|
|
|
150 |
*/
|
|
|
151 |
?>
|