Advertisement
metalx1000

Image GPS LOGGER using EXIF

Feb 20th, 2022
2,245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.88 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #
  4. # This file is part of the Maps-and-Locations (https://github.com/metalx1000/Maps-and-Locations http://FilmsByKris.com).
  5. # Copyright (c) 2022 Kris Occhipinti.
  6. #
  7. # This script creates a log of GPS data for a given image
  8. #
  9. # This program is free software: you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation, version 3.
  12. #
  13. # This program is distributed in the hope that it will be useful, but
  14. # WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. # General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21.  
  22. if [ "$#" -lt 1 ]
  23. then
  24.   echo "input error"
  25.   echo "example usage: $0 photo.jpg"
  26.   exit 1
  27. fi
  28.  
  29. thumbs="thumbs"
  30. smallimg="imgs"
  31. log="img.log"
  32.  
  33. image="$1"
  34. echo -n "$image "
  35.  
  36.  
  37. function noGPS(){
  38.   echo "No GPS Found in Image..."
  39.   exit 1
  40. }
  41.  
  42. exiftool "$image"|grep "GPS Position"||noGPS
  43.  
  44. basename="$(basename "$image")"
  45. exif="$(exiftool "$image")"
  46. md5="$(md5sum "$image"|awk '{print $1}')"
  47. lat="$(echo "$exif"|grep "GPS Position"|cut -d\: -f2|sed 's/ deg /+(/g'|sed "s/' /\/60)+(/"|sed 's/"/\/3600)/'|awk '{print $1}'|bc -l)"
  48. long="-$(echo "$exif"|grep "GPS Position"|cut -d\, -f2|sed 's/ deg /+(/g'|sed "s/' /\/60)+(/"|sed 's/"/\/3600)/'|awk '{print $1}'|bc -l)"
  49. img_date="$(echo "$exif"|grep "^Date"|head -n1|awk '{print $4}'|tr ":" "/")"
  50. img_time="$(echo "$exif"|grep "^Date"|head -n1|awk '{print $5}')"
  51. epoch="$(date -d "$img_date $img_time" +%s)"
  52.  
  53. mkdir -p "$thumbs"
  54. mkdir -p "$smallimg"
  55.  
  56.  
  57. convert "$image" -resize 128 "$thumbs/$basename"
  58. convert "$image" -resize 512 "$smallimg/$basename"
  59. echo "$md5,$basename,$epoch,$img_date,$img_time,$lat,$long" >> "$log"
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement