trying to delete insert same value multiple times in Keywords or Subject

Started by cquiqui, September 12, 2010, 01:33:46 AM

Previous topic - Next topic

cquiqui

Dear Phil,

I am so glad to use your ExifTool Perl API to play with my Metadata in my pictures for my personal usage.

I have found something strange to me, maybe I'm not doing things the right way, please tell me if so, when  inserting  the same value multiple times in Keywords or Subject using the following code, it seems that the value is delete only once and inserted several times:

my $exiftool = new Image::ExifTool;   
my $info = $exiftool->ImageInfo($FilenamePath);

$exiftool->Options(Verbose => '2');

$exiftool->SetNewValue('Keywords' => 'lieux', Group => 'IPTC', DelValue => 1);
$exiftool->SetNewValue('Keywords' => 'lieux', Group => 'IPTC', AddValue => 1);
$exiftool->SetNewValue('Keywords' => 'lieux', Group => 'IPTC', DelValue => 1);
$exiftool->SetNewValue('Keywords' => 'lieux', Group => 'IPTC', AddValue => 1);
$exiftool->SetNewValue('Keywords' => 'lieux', Group => 'IPTC', DelValue => 1);
$exiftool->SetNewValue('Keywords' => 'lieux', Group => 'IPTC', AddValue => 1);
   
my $success = $exiftool->WriteInfo($FilenamePath);
print "Write success=$success\n";

here is what debug information I get:

Deleting IPTC:Keywords from list if value is 'lieux'
Adding IPTC:Keywords
Deleting IPTC:Keywords from list if value is 'lieux'
Adding IPTC:Keywords
Deleting IPTC:Keywords from list if value is 'lieux'
Adding IPTC:Keywords
Rewriting X:\[TESTS PHOTOS]\Perl Img Mgm\IMG_8417.jpg...
  Editing tags in: APP13 IPTC Photoshop
  Creating tags in: APP13 IPTC Photoshop
JPEG APP1 (7888 bytes):
JPEG APP1 (12354 bytes):
JPEG APP13 (556 bytes):
  Rewriting Photoshop
  Rewriting IPTC
    - IPTC:Keywords = 'lieux'
    + IPTC:Keywords = 'lieux'
    + IPTC:Keywords = 'lieux'
    + IPTC:Keywords = 'lieux'
JPEG DQT (130 bytes):
JPEG SOF0:
JPEG DHT (416 bytes):
JPEG SOS
Write success=1


What do you think ?
thank's for your time
best Regards

Jeff



Phil Harvey

Hi Jeff,

This is correct.  Adding multiple DelValue calls for the same value has no effect because you can only remove the value once from a list.  Adding multiple AddValue calls will add multiple values to the list.  It doesn't matter if they are the same value.

What you have done is identical to this:

$exiftool->SetNewValue('Keywords' => ['lieux','lieux','lieux'], Group => 'IPTC', DelValue => 1);
$exiftool->SetNewValue('Keywords' => ['lieux','lieux','lieux'], Group => 'IPTC', AddValue => 1);


(Side note: You can even drop the AddValue from the second call since it is redundant.  Once you use DelValue to delete an individual item from the list, ExifTool automatically assumes you want to preserve the other values.  This assumption will remain in effect until Replace is used.)

The problem is in the way you are thinking.  The calls to SetNewValue aren't like individual operations on the list.  Instead, they set new values to add and delete in a single operation when the image is rewritten.

I hope this makes sense.

- 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 ($).

cquiqui

Thanks' a lot for this answser Phil,

I've got it and after a few tests I could do what I wanted to do.

Jeff :)