Problems adding keywords (XMP-dc:Subject) to JPEG

Started by Archive, May 12, 2010, 08:53:58 AM

Previous topic - Next topic

Archive

[Originally posted by martin on 2006-12-01 18:18:18-08]

Hello,

I am using ExifTool Perl Module 6.57 to add keywords to the XMP-dc:Subject tag of a JPEG:

Code:
my $info = $exifTool->ImageInfo($image, 'XMP:*');
$exifTool->SetNewValue('XMP-dc:Subject' => ['person.jan', 'person.simon']);
my $rc = $exifTool->WriteInfo($image);

This works nice, but when I later try to add another keyword without removing the others:

Code:
my $info = $exifTool->ImageInfo($image, 'XMP:*');
$exifTool->SetNewValue('XMP-dc:Subject' => 'person.beth', AddValue => 1);
my $rc = $exifTool->WriteInfo($image);

nothing happens. The old list is still in place.

I get no errors or warnings.

What am I doing wrong?

Regards

    Martin

Archive

[Originally posted by exiftool on 2006-12-01 18:43:46-08]

Wow.  I can't believe I broke this.  You have discovered a bug which was
introduced in version 6.50 when I tried to fix a related problem.  I will
fix this and version 6.60 should be OK again when it is released.

Thanks for pointing out this problem.

- Phil

Archive

[Originally posted by exiftool on 2006-12-01 20:44:50-08]

I think I have fixed the problem.  If you want to help in testing before 6.60
is released officially, I have uploaded a pre-release version
here.

Thanks again for pointing this out.

Archive

[Originally posted by martin on 2006-12-01 23:19:03-08]

Hi Phil,

thanks for the fast response and the new version!

Mmh, I still see problems, e.g. when I - in a first run - set a certain keyword:

 
Code:
$exifTool->SetNewValue('XMP-dc:Subject' => 'person.jan');

and then in a next run add another keyword:

 
Code:
$exifTool->SetNewValue('XMP-dc:Subject' => 'person.phil', AddValue => 1);

it adds the new keyword, but if I repeat the second step, ExifTool keeps adding the second keyword even if the Duplicates option is set to zero:
 
Code:
$exifTool->Options(Duplicates => 0);

If I combine both statements. It adds both keywords over and over again:

Code:
$exifTool->SetNewValue('XMP-dc:Subject' => 'person.jan');
 $exifTool->SetNewValue('XMP-dc:Subject' => 'person.phil', AddValue => 1);

I would expect, that it just adds the second and even that should be prevented with the Duplicates setting, shouldn't it?

So the behavior seems strange to me as soon as AddValue or DelValue are used somewhere.

Martin

Archive

[Originally posted by exiftool on 2006-12-02 03:06:52-08]

Hi Martin,

Great, thanks for the testing.  It sounds like it
is working as designed.  Now I just have to let you
understand my design... Smiley

First, the Duplicates option only applies to extracted
information, and has nothing to do with writing.

Second, list tags are tricky, so I can understand why you
are a bit confused.  The AddValue and DelValue tags are not
very commonly used since their only purpose is to modify
existing lists.  You don't need to use them to write a new
list with multiple values, which can be done like this:

Code:
$exifTool->SetNewValue('XMP-dc:Subject' => 'person.jan');
$exifTool->SetNewValue('XMP-dc:Subject' => 'person.phil');

If you set the 'AddValue' flag in either of these calls, then
the existing values in the file will be preserved.  So to be
clear, the above two lines of code are equivalent to:

Code:
$exifTool->SetNewValue('XMP-dc:Subject' => ['person.jan', 'person.phil']);

Also, I should mention that after calling WriteInfo(), the cache
of new values to be written remains unchanged -- some people get
confused because they think this resets the new values, and
are suprised when things get duplicated in subsequent calls
to WriteInfo() with the same $exifTool object.)

DelValue is also a bit tricky.  When applied to a list-type tag
it causes the specified value to be deleted from an existing
list.  Logically, this implies that you want to keep all other
values (otherwise you would have just overwritten the entire
list).  So effectively, AddValue is assumed for all other values
when DelValue is used.  This may be a bit confusing at first,
but it should make sense if you think about it.

And to make things even more complicated, the behaviour of these
flags is different for non-list type tags.  But I won't try to
confuse you further by getting into these details since we are
talking about list-type tags here.

Let me know if anything is still unclear after you think about
this for a bit.

- Phil