strip_image_metadata.sh 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env sh
  2. : '
  3. Requirements: `exiftool`
  4. This script makes use of exiftool to remove metadata from a file.
  5. Undesirable metadata might include author, operating system,
  6. version of image editor used to create an image, geolocation, etc.
  7. Often this information is present in files without our knowledge
  8. or assent so it is a good idea to proactively remove it using
  9. this script of exiftool directly.
  10. Exiftool works well for removing metadata from images. However,
  11. it cannot completely remove metadata from PDFs. See the exiftool
  12. docs for more information.
  13. This script should be run before a file is committed to
  14. the repository.
  15. It can be run non-destructively as exiftool will create a copy
  16. of the original file and preserve it with the string "_original"
  17. appended to the end.
  18. e.g. `test.jpg` as input to exiftool will create `test.jpg_original`.
  19. This script is simple and removes metadata only from a single file.
  20. However, it is absolutely possible to use exitool in conjunction with
  21. `find` and a `for` loop to remove metadata, either using this tool
  22. or with exiftool directly.
  23. '
  24. set -e
  25. if [ "$#" -ne 1 ]; then
  26. echo "Usage: $0 <file>"
  27. exit 1
  28. fi
  29. FILE="$1"
  30. if ! [ -f $FILE ]; then
  31. echo "Target should be a file"
  32. exit 2
  33. else
  34. exiftool -all= $FILE
  35. fi