There is a bug in exiftool
where reading and writing the longitude is not consistent. So I wrote a Perl script to do it another way that bypasses the bug (see bug description below script):
#!/usr/bin/perl
use strict;
die "usage: src.jpg dst.jpg" unless @ARGV == 2;
my ($SRC, $DST) = ($ARGV[0], $ARGV[1]);
my @GPS = `exiftool -c "%.12f" -gpslatitude -gpslongitude $SRC`;
my $N = @GPS;
die "No GPS data in $SRC\n" unless $N >= 2;
my ($LAT,$LON,$NS,$EW) = (0,0,"N","W");
if ($GPS[0] =~ /Lat[^\d]*(\d+\.\d+?)\ ([NS])/) {
$LAT = $1;
$NS = $2;
}
if ($GPS[1] =~ /Lon[^\d]*(\d+\.\d+)\ ([EW])/) {
$LON = $1;
$EW = $2;
}
my $LATREF = $NS eq "N" ? "North" : "South";
my $LONREF = $EW eq "E" ? "East" : "West";
my $CMD = "exiftool -GPSLatitude=$LAT -GPSLongitude=$LON -GPSLongitudeRef=\"$LONREF\" -GPSLatitudeRef=\"$LATREF\" \"$DST\"";
system($CMD) == 0 or die "$!\n";
By the way, the exiftool
bug is here on the following line
$deg = -$deg if $doSign ? $val =~ /[^A-Z](S(outh)?|W(est)?)\s*$/i : $deg < 0;
which fails when $doSign
is undef
which is what is passed on the line
PrintConvInv => 'Image::ExifTool::GPS::ToDegrees($val,undef,"lat")',