15

I have a camera (not a cellphone) that inserts gps exif info into pictures.

Fact is: using the "gps on" all time drains the battery. So i thought: what about taking just one picture with gps on, and them at home add this exif info to the others?

I would like to know if there are applications that you know of that can help me in this scenario: having a photo with exif information about gps, copy this same gps info to a batch of another pictures.

(I prefer Linux/Mac solutions, but I accept windows as well. I don't mind if it's a command line application.)

3 Answers3

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}"
haimg
  • 23,153
  • 17
  • 83
  • 117
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.

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