ExifTool Forum

ExifTool => The Image::ExifTool API => Topic started by: dkdayton on December 27, 2010, 07:06:33 PM

Title: Replacing Keywords using the API
Post by: dkdayton on December 27, 2010, 07:06:33 PM
I am using perl and the api to replace tags on a large collection of photographs.  I can replace single value tags, but I can't figure out how to replace old tags in lists such as keywords.  The old items remain and the new items are appended on the end of the list.  Any suggestions?
Title: Re: Replacing Keywords using the API
Post by: Phil Harvey on December 28, 2010, 08:19:02 AM
I think that reading FAQ number 17 (https://exiftool.org/faq.html#Q17) may help.  Let me know if you have any questions after reading this.

- Phil
Title: Re: Replacing Keywords using the API
Post by: dkdayton on December 30, 2010, 12:41:05 PM
Thanks for the response. 

I read FAQ 17, but it discussed the issue issue in the context of the EXIFTOOL application.  I understand generally how list tags work, but I still don't know how to solve my specific problem.  I have some existing keyword tags in a large number of files that I want to delete using Perl and the EXIFTOOL library (not the application).  Is there a way to use the EXIF Library to delete all of the existing values for the keyword field, so that I can repopulate the field with only the values that I want to have there?

Thanks again.
Title: Re: Replacing Keywords using the API
Post by: Phil Harvey on December 30, 2010, 12:49:17 PM
Via the API, you do this to replace existing keywords:

$exifTool->SetNewValue(Keywords => 'word1');
$exifTool->SetNewValue(Keywords => 'word2');


or equivalently:

$exifTool->SetNewValue(Keywords => ['word1', 'word2']);

This is one of the examples in the SetNewValue() documentation (https://exiftool.org/ExifTool.html#SetNewValue).

Does this clear things up?

- Phil
Title: Re: Replacing Keywords using the API
Post by: dkdayton on December 30, 2010, 01:18:55 PM
I am able to ADD keywords using that method.  The problem is that I don't seem to be able to remove existing keywords that I no longer want in the list.

An example might help.  Old keywords (oldword1 and oldword2 exist in the file) before I process it to add newword1 and newword2.  When I use the method you suggest, the list becomes: oldword1, oldword2, newword1, newword2.  I want it to be newword1, newword2.  How do I delete oldword1 and oldword2?

Deane
Title: Re: Replacing Keywords using the API
Post by: Phil Harvey on December 30, 2010, 04:17:23 PM
Hi Deane,

The method I suggested does delete oldword1 and oldword2.  You must specifically use the AddValue option if you want to preserve existing values.

If it doesn't work this way for you, there is something odd happening.  In this case a sample file and code snippet would be useful.

- Phil