Double XMP entry in file

Started by tbraber, March 15, 2011, 09:58:48 AM

Previous topic - Next topic

tbraber

I have a jpeg file with the xmp description in the file that looks like:

<rdf:Description rdf:about=''
  xmlns:dc='http://purl.org/dc/elements/1.1/'>
  <dc:description> 4.0.1</dc:description>
</rdf:Description>

Exiftool reads this correctly but when I edit the dc:description it ads an extra dc:description block:

<rdf:Description rdf:about=''
  xmlns:dc='http://purl.org/dc/elements/1.1/'>
  <dc:description> 4.0.1</dc:description>
  <dc:description>
   <rdf:Alt>
    <rdf:li xml:lang='x-default'>test</rdf:li>
   </rdf:Alt>
  </dc:description>
</rdf:Description>

Why does it not edit the existing tag instead of adding an extra tag ?
I am using Exiftool 8.45

Phil Harvey

This happens because the existing description is written incorrectly.  It should be enclosed in an alternate language list.

ExifTool is very tolerant of unrecognized XMP, and will generally just pass it straight through when writing.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

tbraber

Phil,

could there be a way that Exiftool removed the original dc:description and replaces that with the correct one ?
Maybe by deleting the complete xmp recourse and rebuilding it again.

Thanks for your reply,
Thomas

Phil Harvey

Hi Thomas,

Yes, you can rebuild the XMP with this command:

exiftool -xmp:all= -tagsfromfile @ -xmp:all FILE

This will delete any XMP tags that are not writable by ExifTool.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

tbraber

Do you have any suggestion how to do that in Perl with the Perl Library ?

Thanks,

Thomas den Braber

Phil Harvey

Hi Thomas,

Sure:

    $exifTool->SetNewValue('xmp:all');
    $exifTool->SetNewValuesFromFile($srcFile, 'xmp:all');
    $exifTool->WriteInfo($srcFile, $outFile);


- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

tbraber

Thanks,

That worked really well, it fixed my double entries.

I was hoping that:


$exifTool->SetNewValue('XMP:all');
$exifTool->SetNewValue('XMP:all', undef, Replace => 2)


also would work because I already read the info from the file with $exifTool->ExtractInfo

I assume that SetNewValuesFromFile will add some more overhead.


Phil Harvey

You could avoid the extra step of calling SetNewValuesFromFile(), but it would require calling SetNewValue() for each value you want to write, something like this:

my $exifTool = new Image::ExifTool;
$exifTool->ExtractInfo($srcFile);
my $info = $exifTool->GetInfo('XMP:all');

$exifTool->SetNewValue('XMP:all');
foreach my $key (keys %$info) {
    $exifTool->SetNewValue($key, $$info{$key}, Group => 'XMP');
}
$exifTool->WriteInfo($srcFile, $dstFile);


Note that you will get some warnings to stderr with this code since I haven't set the Protected flag or captured the warnings from SetNewValue().

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).