News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

SetNewValue() not working when field does not already exist

Started by frank, April 25, 2020, 10:17:30 AM

Previous topic - Next topic

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.


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


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