1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008 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'; |
---|
25 | echo '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 | */ |
---|
33 | function 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(); |
---|
48 | getimagesize($filename, $imginfo); |
---|
49 | if (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 | } |
---|
86 | else |
---|
87 | { |
---|
88 | echo 'no IPTC information'; |
---|
89 | } |
---|
90 | |
---|
91 | echo '<br /><br /><br />'; |
---|
92 | echo 'EXIF Fields in '.$filename.'<br />'; |
---|
93 | $exif = read_exif_data($filename); |
---|
94 | echo '<pre>'; |
---|
95 | print_r($exif); |
---|
96 | echo '</pre>'; |
---|
97 | ?> |
---|