[493] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[675] | 5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[493] | 6 | // +-----------------------------------------------------------------------+ |
---|
[593] | 7 | // | branch : BSF (Best So Far) |
---|
[1113] | 8 | // | file : $Id: functions_metadata.inc.php 1900 2007-03-12 22:33:53Z rub $ |
---|
[493] | 9 | // | last update : $Date: 2007-03-12 22:33:53 +0000 (Mon, 12 Mar 2007) $ |
---|
| 10 | // | last modifier : $Author: rub $ |
---|
| 11 | // | revision : $Revision: 1900 $ |
---|
| 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 | */ |
---|
| 35 | function get_iptc_data($filename, $map) |
---|
| 36 | { |
---|
| 37 | $result = array(); |
---|
[1113] | 38 | |
---|
[493] | 39 | $imginfo = array(); |
---|
[1711] | 40 | if (false == @getimagesize($filename, $imginfo) ) |
---|
| 41 | { |
---|
| 42 | return $result; |
---|
| 43 | } |
---|
[1113] | 44 | |
---|
[493] | 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 | { |
---|
[611] | 53 | if (isset($iptc[$iptc_key][0])) |
---|
[493] | 54 | { |
---|
[611] | 55 | if ($iptc_key == '2#025') |
---|
[493] | 56 | { |
---|
[611] | 57 | $value = implode(',', |
---|
| 58 | array_map('clean_iptc_value',$iptc[$iptc_key])); |
---|
[493] | 59 | } |
---|
[611] | 60 | else |
---|
| 61 | { |
---|
| 62 | $value = clean_iptc_value($iptc[$iptc_key][0]); |
---|
| 63 | } |
---|
| 64 | |
---|
[493] | 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 | } |
---|
[611] | 75 | |
---|
| 76 | /** |
---|
| 77 | * return a cleaned IPTC value |
---|
| 78 | * |
---|
| 79 | * @param string value |
---|
| 80 | * @return string |
---|
| 81 | */ |
---|
| 82 | function clean_iptc_value($value) |
---|
| 83 | { |
---|
| 84 | // strip leading zeros (weird Kodak Scanner software) |
---|
[1113] | 85 | while ( isset($value[0]) and $value[0] == chr(0)) |
---|
[611] | 86 | { |
---|
| 87 | $value = substr($value, 1); |
---|
| 88 | } |
---|
| 89 | // remove binary nulls |
---|
| 90 | $value = str_replace(chr(0x00), ' ', $value); |
---|
[1113] | 91 | |
---|
[611] | 92 | return $value; |
---|
| 93 | } |
---|
[858] | 94 | |
---|
| 95 | /** |
---|
| 96 | * returns informations from EXIF metadata, mapping is done at the beginning |
---|
| 97 | * of the function |
---|
| 98 | * |
---|
| 99 | * @param string $filename |
---|
| 100 | * @return array |
---|
| 101 | */ |
---|
| 102 | function get_exif_data($filename, $map) |
---|
| 103 | { |
---|
| 104 | $result = array(); |
---|
| 105 | |
---|
| 106 | if (!function_exists('read_exif_data')) |
---|
| 107 | { |
---|
| 108 | die('Exif extension not available, admin should disable exif use'); |
---|
| 109 | } |
---|
[1113] | 110 | |
---|
[858] | 111 | // Read EXIF data |
---|
| 112 | if ($exif = @read_exif_data($filename)) |
---|
| 113 | { |
---|
| 114 | foreach ($map as $key => $field) |
---|
| 115 | { |
---|
| 116 | if (strpos($field, ';') === false) |
---|
| 117 | { |
---|
| 118 | if (isset($exif[$field])) |
---|
| 119 | { |
---|
| 120 | $result[$key] = $exif[$field]; |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | else |
---|
| 124 | { |
---|
| 125 | $tokens = explode(';', $field); |
---|
| 126 | if (isset($exif[$tokens[0]][$tokens[1]])) |
---|
| 127 | { |
---|
| 128 | $result[$key] = $exif[$tokens[0]][$tokens[1]]; |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | } |
---|
| 132 | } |
---|
| 133 | |
---|
| 134 | return $result; |
---|
| 135 | } |
---|
[493] | 136 | ?> |
---|