metalx1000

Modify Image EXIF data

Jan 19th, 2022 (edited)
1,020
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.71 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2022  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. #this script modifies exif values of an image
  21. #such as the GPSZAccuracy
  22. #based on info found here:
  23. #https://exiftool.org/metafiles.html
  24.  
  25. if [[ $* < 1 ]]
  26. then
  27.   echo "Useage: $0 <image> <value1> <value 2>"
  28.   echo "Example: $0 100_10_01.jpg 5.5 3.3"
  29.   exit 1
  30. fi
  31.  
  32. img="$1"
  33. gpsz="$2"
  34. gpsxy="$3"
  35.  
  36. #display original value
  37. echo "Original Value:"
  38. exiftool -s $img | grep GPS|grep Accuracy
  39.  
  40. #dump xmp data to xml formatted file
  41. exiftool -xmp -b "$img" > DST.xmp
  42. gpszo="$(grep "Camera:GPSZAccuracy" DST.xmp)"
  43. gpszn="<Camera:GPSZAccuracy>$gpsz</Camera:GPSZAccuracy>"
  44. gpsxyo="$(grep "Camera:GPSXYAccuracy" DST.xmp)"
  45. gpsxyn="<Camera:GPSXYAccuracy>$gpsxy</Camera:GPSXYAccuracy>"
  46.  
  47. #update value
  48. sed -i "s|$gpszo|$gpszn|g;s|$gpsxyo|$gpsxyn|g" DST.xmp
  49.  
  50. #restore it to img
  51. exiftool -tagsfromfile DST.xmp -xmp "$img"
  52.  
  53. echo "New Value:"
  54. exiftool -s $img | grep GPS|grep Accuracy
  55.  
Add Comment
Please, Sign In to add comment