/** * returns informations from IPTC metadata, mapping is done in this function. * * @param string $filename * @param array $map * @return array */ function get_iptc_data($filename, $map, $array_sep = ',') { global $conf; $result = array(); $imginfo = array(); if (false == @getimagesize($filename, $imginfo)) { return $result; } if (isset($imginfo['APP13'])) { $iptc = iptcparse($imginfo['APP13']); if (is_array($iptc)) { $rmap = array_flip($map); foreach (array_keys($rmap) as $iptc_key) { if (isset($iptc[$iptc_key][0])) { if ($iptc_key == '2#025') { $value = implode($array_sep, array_map('clean_iptc_value', $iptc[$iptc_key])); } else { $value = clean_iptc_value($iptc[$iptc_key][0]); } foreach (array_keys($map, $iptc_key) as $pwg_key) { $result[$pwg_key] = $value; if (!$conf['allow_html_in_metadata']) { // in case the origin of the photo is unsecure (user upload), we // remove HTML tags to avoid XSS (malicious execution of // javascript) $result[$pwg_key] = strip_tags($result[$pwg_key]); } } } } } } return $result; }
// remove binary nulls $value = str_replace(chr(0x0), ' ', $value); return $value; } $iptc_result = array(); $imginfo = array(); getimagesize($filename, $imginfo); if (isset($imginfo['APP13'])) { $iptc = iptcparse($imginfo['APP13']); if (is_array($iptc)) { foreach (array_keys($iptc) as $iptc_key) { if (isset($iptc[$iptc_key][0])) { if ($iptc_key == '2#025') { $value = implode(',', array_map('clean_iptc_value', $iptc[$iptc_key])); } else { $value = clean_iptc_value($iptc[$iptc_key][0]); } $iptc_result[$iptc_key] = $value; } } } echo 'IPTC Fields in ' . $filename . '<br>'; $keys = array_keys($iptc_result); sort($keys); foreach ($keys as $key) { echo '<br>' . $key . ' = ' . $iptc_result[$key]; } } else { echo 'no IPTC information'; } echo '<br><br><br>';