2025-07-02: ExifTool 13.32 is now available
using the exiftool api, write perl code to adjust all time fields in the metadata to the photo's location coordinates relative to central standard time
#!/usr/bin/perl
use strict;
use warnings;
use Image::ExifTool qw(:Public);
use DateTime::TimeZone; # You'll need to install this Perl module
# Define the directory containing your image files
my $image_directory = "/path/to/your/images";
# Create a new ExifTool object
my $exifTool = new Image::ExifTool;
# Get a list of image files in the directory (you can adjust this to suit your needs)
my @image_files = <$image_directory/*.jpg>;
foreach my $file (@image_files) {
# Extract metadata including GPS coordinates and timestamps
my $info = $exifTool->ImageInfo($file);
# Check if GPS coordinates are available
if ($info->{GPSLatitude} && $info->{GPSLongitude}) {
my $latitude = $info->{GPSLatitude};
my $longitude = $info->{GPSLongitude};
# Attempt to get the timezone from coordinates using DateTime::TimeZone
# You'll need a way to map coordinates to a timezone name (e.g., using a library or service)
# This example uses a placeholder, you'll need to implement the actual logic
my $timezone_name = get_timezone_from_coordinates($latitude, $longitude);
if ($timezone_name) {
# Create DateTime::TimeZone object
my $location_timezone = DateTime::TimeZone->new(name => $timezone_name);
# Iterate through time-related tags that might have CST timestamps
my @time_tags = qw(DateTimeOriginal CreateDate ModifyDate); # Adjust the list of tags as needed
foreach my $tag (@time_tags) {
if ($info->{$tag}) {
# Get the original timestamp string (assuming it's in CST, you might need to adjust this)
my $timestamp_str = $info->{$tag};
# Assuming timestamp format "YYYY:MM:DD HH:MM:SS" (adjust if needed)
if ($timestamp_str =~ /(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})/) {
my ($year, $month, $day, $hour, $minute, $second) = ($1, $2, $3, $4, $5, $6);
# Create a DateTime object in the original timezone (CST, adjust if needed)
my $original_dt = DateTime->new(
year => $year,
month => $month,
day => $day,
hour => $hour,
minute => $minute,
second => $second,
time_zone => 'America/Chicago' # Assuming CST is America/Chicago
);
# Convert the DateTime object to the location's timezone
$original_dt->set_time_zone($location_timezone);
# Format the adjusted timestamp for ExifTool (YYYY:MM:DD HH:MM:SS[+-]HH:MM)
my $adjusted_timestamp = $original_dt->ymd(':') . ' ' . $original_dt->hms(':') . $original_dt->strftime('%z');
# Update the timestamp tag with the adjusted value and timezone
$exifTool->SetNewValue($tag, $adjusted_timestamp);
}
}
}
# Write the changes to the file
$exifTool->WriteInfo($file);
print "Adjusted timestamps for $file to $timezone_name\n";
} else {
print "Could not determine timezone for $file from GPS coordinates\n";
}
} else {
print "No GPS coordinates found for $file\n";
}
}
# Subroutine to get timezone name from latitude and longitude (placeholder)
# You'll need to implement this logic using a library or external service
sub get_timezone_from_coordinates {
my ($latitude, $longitude) = @_;
# Example placeholder: replace with your timezone lookup logic
# You might use a library like Geo::Timezone or an API call to a geolocation service
return "Europe/Berlin"; # Replace with actual timezone name based on coordinates
}
my $timestamp_str = $info->{$tag};
Quote from: antb on July 06, 2025, 05:28:04 AMwith version exiftool-10.07
C:\>exiftool -G1 -a -s --system:all -file:all Y:\!temp\x\y\20250302_144047.170_CR5m2-8486.HIF
[File] FileType : HEIF
[File] FileTypeExtension : heif
[File] MIMEType : image/heif
[File] ExifByteOrder : Little-endian (Intel, II)
[File] ImageWidth : 8192
[File] ImageHeight : 5464