Created
November 12, 2023 22:43
-
-
Save keiranlovett/62fffa7552007af5d638d66da0ca0bae to your computer and use it in GitHub Desktop.
./batchUpdateExifGeo.sh /path/to/directory latitude longitude elevation latRef longRef
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
# Check if ExifTool is installed | |
if ! command -v exiftool &> /dev/null; then | |
echo "Error: ExifTool is not installed. Please install it before running this script." | |
echo "You can install it using Homebrew: brew install exiftool" | |
exit 1 | |
fi | |
# Check if the user provided a directory and GPS coordinates as arguments | |
if [ "$#" -lt 7 ]; then | |
echo "Error: Insufficient arguments. Please provide a directory and GPS coordinates." | |
echo "Usage: $0 <directory> <new_latitude> <new_longitude> <new_altitude> <latitude_ref> <longitude_ref>" | |
exit 1 | |
fi | |
# Set the directory and GPS variables from the user's input | |
directory="$1" | |
new_latitude="$2" | |
new_longitude="$3" | |
new_altitude="$4" | |
latitude_ref="$5" | |
longitude_ref="$6" | |
# Check if the provided directory exists | |
if [ ! -d "$directory" ]; then | |
echo "Error: The specified directory '$directory' does not exist." | |
exit 1 | |
fi | |
# Count of processed files | |
file_count=0 | |
# Move to the specified directory | |
cd "$directory" || exit | |
# Iterate through all JPEG files in the directory | |
for file in *.jpg; do | |
echo "Processing $file" | |
# Print existing GPS information | |
echo "Existing GPS Information:" | |
exiftool -gpslatitude -gpslongitude -gpsaltitude -gps:GPSLatitudeRef -gps:GPSLongitudeRef "$file" | |
# Update GPS information in JPEG file | |
exiftool -gpslatitude="$new_latitude" -gpslongitude="$new_longitude" -gpsaltitude="$new_altitude" -gps:GPSLatitudeRef="$latitude_ref" -gps:GPSLongitudeRef="$longitude_ref" "$file" | |
# Update or create XMP sidecar file | |
exiftool -gpslatitude="$new_latitude" -gpslongitude="$new_longitude" -gpsaltitude="$new_altitude" -gps:GPSLatitudeRef="$latitude_ref" -gps:GPSLongitudeRef="$longitude_ref" -o "$file.xmp" -overwrite_original "$file" | |
# Print new GPS information | |
echo "Updated GPS Information:" | |
exiftool -gpslatitude -gpslongitude -gpsaltitude -gps:GPSLatitudeRef -gps:GPSLongitudeRef "$file" | |
echo "-------------------------" | |
# Increment the file count | |
((file_count++)) | |
done | |
# Print the total number of processed files | |
echo "Total number of files processed: $file_count" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick and dirty script to help me update the geolocation of some photos.
./batchUpdateExifGeo.sh /path/to/directory latitude longitude elevation latRef longRef