17
17
my $longitude = 22.796479967835673;
18
18
19
19
my $coordinates = undef ;
20
+ my $force = 0;
20
21
my $set_gps = 0;
21
22
my $utc_offset = 0;
22
23
@@ -34,6 +35,7 @@ ($exit_code = 0)
34
35
35
36
options:
36
37
--gps! : set the GPS coordinates
38
+ --force! : overwrite the EXIF creation date
37
39
--latitude=float : value for GPSLatitude
38
40
--longitude=float : value for GPSLongitude
39
41
--coordinates=str : GPS coordinates as "latitude,longitude"
@@ -47,6 +49,7 @@ ($exit_code = 0)
47
49
48
50
GetOptions(
49
51
" gps!" => \$set_gps ,
52
+ " force!" => \$force ,
50
53
" f|formats=s" => \$img_formats ,
51
54
" utc-offset=i" => \$utc_offset ,
52
55
" latitude=f" => \$latitude ,
@@ -70,13 +73,22 @@ ($file)
70
73
my ($year , $month , $day , $hour , $min , $sec ) = ($1 , $2 , $3 , $4 , $5 , $6 );
71
74
72
75
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
+
73
85
say " Setting image creation time to: $date " ;
74
86
75
87
# Set the file modification date
76
88
$exifTool -> SetNewValue(FileModifyDate => $date , Protected => 1);
77
89
78
90
# 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" )) {
80
92
$exifTool -> SetNewValue(DateTimeOriginal => $date );
81
93
}
82
94
@@ -88,12 +100,6 @@ ($file)
88
100
$exifTool -> SetNewValue(' GPSLongitudeRef' , $longitude >= 0 ? ' E' : ' W' );
89
101
}
90
102
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
-
97
103
my ($dev , $ino , $mode , $nlink , $uid , $gid , $rdev , $size , $atime , $mtime , $ctime , $blksize , $blocks ) = stat ($file );
98
104
99
105
$exifTool -> WriteInfo($file );
0 commit comments