Skip to content

Commit c0a203d

Browse files
committed
modified: Image/add_exif_info.pl -- added the --force flag and fixed an issue with --utc-offset.
1 parent 9ffa728 commit c0a203d

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Image/add_exif_info.pl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
my $longitude = 22.796479967835673;
1818

1919
my $coordinates = undef;
20+
my $force = 0;
2021
my $set_gps = 0;
2122
my $utc_offset = 0;
2223

@@ -34,6 +35,7 @@ ($exit_code = 0)
3435
3536
options:
3637
--gps! : set the GPS coordinates
38+
--force! : overwrite the EXIF creation date
3739
--latitude=float : value for GPSLatitude
3840
--longitude=float : value for GPSLongitude
3941
--coordinates=str : GPS coordinates as "latitude,longitude"
@@ -47,6 +49,7 @@ ($exit_code = 0)
4749

4850
GetOptions(
4951
"gps!" => \$set_gps,
52+
"force!" => \$force,
5053
"f|formats=s" => \$img_formats,
5154
"utc-offset=i" => \$utc_offset,
5255
"latitude=f" => \$latitude,
@@ -70,13 +73,22 @@ ($file)
7073
my ($year, $month, $day, $hour, $min, $sec) = ($1, $2, $3, $4, $5, $6);
7174

7275
my $date = "$year:$month:$day $hour:$min:$sec";
76+
77+
my $time_format = "%Y:%m:%d %H:%M:%S";
78+
my $time_obj = Time::Piece->strptime($date, $time_format);
79+
80+
if ($utc_offset) {
81+
$time_obj += $utc_offset * 3600;
82+
$date = $time_obj->strftime($time_format);
83+
}
84+
7385
say "Setting image creation time to: $date";
7486

7587
# Set the file modification date
7688
$exifTool->SetNewValue(FileModifyDate => $date, Protected => 1);
7789

7890
# Set the EXIF creation date (unless it already exists)
79-
if (not defined $exifTool->GetValue("DateTimeOriginal")) {
91+
if ($force or not defined $exifTool->GetValue("DateTimeOriginal")) {
8092
$exifTool->SetNewValue(DateTimeOriginal => $date);
8193
}
8294

@@ -88,12 +100,6 @@ ($file)
88100
$exifTool->SetNewValue('GPSLongitudeRef', $longitude >= 0 ? 'E' : 'W');
89101
}
90102

91-
my $time_obj = Time::Piece->strptime($date, "%Y:%m:%d %H:%M:%S");
92-
93-
if ($utc_offset) {
94-
$time_obj += $utc_offset * 3600;
95-
}
96-
97103
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime, $ctime, $blksize, $blocks) = stat($file);
98104

99105
$exifTool->WriteInfo($file);

0 commit comments

Comments
 (0)