mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-03-28 17:42:57 +01:00
bug 339 fixed: crash on metadata synchronization when duplicate keywords.
improvement: tools/metadata.php is nearer of what metadata synchronization uses (concerning keywords) git-svn-id: http://piwigo.org/svn/branches/branch-1_6@1222 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
@@ -53,6 +53,16 @@ function get_sync_iptc_data($file)
|
||||
// official keywords separator is the comma
|
||||
$iptc['keywords'] = preg_replace('/[.;]/', ',', $iptc['keywords']);
|
||||
$iptc['keywords'] = preg_replace('/^,+|,+$/', '', $iptc['keywords']);
|
||||
|
||||
$iptc['keywords'] = implode(
|
||||
',',
|
||||
array_unique(
|
||||
explode(
|
||||
',',
|
||||
$iptc['keywords']
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return $iptc;
|
||||
|
||||
@@ -28,6 +28,25 @@
|
||||
$filename = 'sample.jpg';
|
||||
echo 'Informations are read from '.$filename.'<br /><br /><br />';
|
||||
|
||||
/**
|
||||
* return a cleaned IPTC value
|
||||
*
|
||||
* @param string value
|
||||
* @return string
|
||||
*/
|
||||
function clean_iptc_value($value)
|
||||
{
|
||||
// strip leading zeros (weird Kodak Scanner software)
|
||||
while ( isset($value[0]) and $value[0] == chr(0))
|
||||
{
|
||||
$value = substr($value, 1);
|
||||
}
|
||||
// remove binary nulls
|
||||
$value = str_replace(chr(0x00), ' ', $value);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
$iptc_result = array();
|
||||
$imginfo = array();
|
||||
getimagesize($filename, $imginfo);
|
||||
@@ -38,17 +57,25 @@ if (isset($imginfo['APP13']))
|
||||
{
|
||||
foreach (array_keys($iptc) as $iptc_key)
|
||||
{
|
||||
if (isset($iptc[$iptc_key][0]) and $value = $iptc[$iptc_key][0])
|
||||
if (isset($iptc[$iptc_key][0]))
|
||||
{
|
||||
// strip leading zeros (weird Kodak Scanner software)
|
||||
while ($value[0] == chr(0))
|
||||
if ($iptc_key == '2#025')
|
||||
{
|
||||
$value = substr($value, 1);
|
||||
$value = implode(
|
||||
',',
|
||||
array_map(
|
||||
'clean_iptc_value',
|
||||
$iptc[$iptc_key]
|
||||
)
|
||||
);
|
||||
}
|
||||
// remove binary nulls
|
||||
$value = str_replace(chr(0x00), ' ', $value);
|
||||
else
|
||||
{
|
||||
$value = clean_iptc_value($iptc[$iptc_key][0]);
|
||||
}
|
||||
|
||||
$iptc_result[$iptc_key] = $value;
|
||||
}
|
||||
$iptc_result[$iptc_key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user