Problem with tag qualifiers

Started by Tom Cunningham, July 05, 2025, 08:07:07 PM

Previous topic - Next topic

Tom Cunningham

#15
Ok, I simplified the code and put it in its own script:

#!/usr/bin/perl

use strict;
use warnings;
use Image::ExifTool qw(:Public);

# Create a new ExifTool object
my $exifTool = new Image::ExifTool;
my $file = 'pic.jpg';
my $info = $exifTool->ImageInfo($file);

my $success = 0;
my $errStr = "";
my $timestamp = '2025:06:16 21:41:49-07:00';

$exifTool->Options(Verbose => 2);

my @time_tags = qw(
                  Sony:SonyDateTime
                  XMP-exif:DateTimeDigitized
                  XMP-exif:DateTimeOriginal
                  XMP-xmp:ModifyDate
                  );

# Iterate through time-related tags
foreach my $tag (@time_tags) {
    my $timestamp_str = $exifTool->GetValue($tag);
    ($success, $errStr) = $exifTool->SetNewValue($tag, $timestamp);
    print '$success = ' . $success . "\n";
}

For output, I get:

Writing Sony:SonyDateTime if tag exists
Writing Sony:SonyDateTime if tag exists
Writing Sony:SonyDateTime if tag exists
Writing Sony:SonyDateTime if tag exists
Writing Sony:SonyDateTime if tag exists
$success = 5
Writing XMP-exif:DateTimeDigitized
$success = 1
Writing XMP-exif:DateTimeOriginal
$success = 1
Writing XMP-xmp:ModifyDate
$success = 1

which, apart from the 5 Sony:SonyDateTime writes (?!), is as expected. When I run the original script (quoted in post #13 above, the only changes being updating the time_tags to match this script, and adding a $exifTool->Options(Verbose => 2 and a print of the $success value), I get this:

$success = 0
$success = 0
$success = 0
$success = 0

Why would this script work, and not the original?

Phil Harvey

I don't see anything obvious.  I suggest printing the arguments of the call to SetNewValue to be sure they are the same in both cases.

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