The Computer Oracle

Transfer exif gps info from one image to another

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Take control of your privacy with Proton's trusted, Swiss-based, secure services.
Choose what you need and safeguard your digital life:
Mail: https://go.getproton.me/SH1CU
VPN: https://go.getproton.me/SH1DI
Password Manager: https://go.getproton.me/SH1DJ
Drive: https://go.getproton.me/SH1CT


Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 2

--

Chapters
00:00 Transfer Exif Gps Info From One Image To Another
00:43 Accepted Answer Score 16
02:08 Answer 2 Score 1
02:25 Answer 3 Score 0
03:06 Thank you

--

Full question
https://superuser.com/questions/377431/t...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#images #gps #pictures #exif

#avk47



ACCEPTED ANSWER

Score 16


Take a look at ExifTool. It is a swiss army knife of Exif info manipulation, can do what you need, among many other things. It is Windows/Linux/Mac compatible command-line tool and a Perl module as well. Free and open source:

The "-tagsFromFile" Option

A special ExifTool option allows copying tags from one file to another. The command-line syntax for doing this is "-tagsFromFile SRCFILE". Any tags specified after this option on the command line are extracted from source file and written to the destination file. If no tags are specified, then all writable tags are copied. This option is very simple, yet very powerful. Depending on the formats of the source and destination files, some of tags read may not be valid in the destination file, in which case they aren't written.

The following command will change all files in current directory and its children (recursively), copying all GPS-related tags from the file SOURCE.JPG:

exiftool −overwrite_original_in_place -r -tagsFromFile SOURCE.JPG -gps:all .

Another way to do this is to put the following into a script. First parameter passed should be the file to copy GPS coordinates from, and all other parameters are the target files to be updated:

#!/usr/bin/env bash
lon=$(exiftool -s3 -GPSLongitude "$1")
lat=$(exiftool -s3 -GPSLatitude "$1")
exiftool -GPSLongitude="$lon" -GPSLatitude="$lat" "${@:2}"



ANSWER 2

Score 1


You can also use exiv2 - it's much faster and, for example, can write exif data to webp images (and others).

exiv2 -PkV --grep GPSL source.jpg | exiv2 -m- destination.webp

This is example from exiv2 board.




ANSWER 3

Score 0


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")',