ExifTool > The Image::ExifTool API

SetNewValue() not working when field does not already exist

(1/1)

frank:
Hi Phil,

Sorry to bother you with this.. I'm not a Perl programmer and I just can't get this to work.

I'm using the API to set the value of DateTimeOriginal and DateTimeDigitized and it works like a charm.. as long as the tags already exist in the image file.


--- Code: ---my $exifTool = new Image::ExifTool;
$exifTool->Options(IgnoreMinorErrors => 1);
$exifTool->SetNewValue(DateTimeOriginal => $value);
$success = $exifTool->WriteInfo($path);

--- End code ---

If the tags don't already exist, nothing happens. What I want to do is add the tag if it does not already exist and replace it if it does.

I have found the DelValue & AddValue flags (not sure what you call them in Perl), but the DelValue seems to require the current value (which I'd prefer not reading unnecessary) and the AddValue flag only works on list types.

How do I express the "add or replace" semantics correctly?

Best regards,

Frank

Phil Harvey:
Hi Frank,

The code you posted will write EXIF:DateTimeOriginal even if it didn't already exist, unless there was some error writing the EXIF.  Check the return code from WriteInfo() and $exifTool->GetValue('Error') to see if there were any errors.

- Phil

Navigation

[0] Message Index

Go to full version