remove_sensitive_exif_tags.pl 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/usr/bin/perl
  2. # Daniel "Trizen" Șuteu
  3. # Date: 09 October 2019
  4. # https://github.com/trizen
  5. # Remove sensitive EXIF information from images that may be used for online-tracking.
  6. # The script uses the "exiftool".
  7. # https://www.sno.phy.queensu.ca/~phil/exiftool/
  8. # This is particularly necessary for photos downloaded from Facebook, which include a tracking ID inside them.
  9. # https://news.ycombinator.com/item?id=20427007
  10. # https://dustri.org/b/on-facebooks-pictures-watermarking.html
  11. # https://www.hackerfactor.com/blog/index.php?/archives/726-Facebook-Tracking.html
  12. # https://www.reddit.com/r/privacy/comments/ccndcq/facebook_is_embedding_tracking_data_inside_the/
  13. use 5.020;
  14. use warnings;
  15. use File::Find qw(find);
  16. use Getopt::Std qw(getopts);
  17. use experimental qw(signatures);
  18. my %opts;
  19. getopts('ea', \%opts); # flag "-e" removes extra tags
  20. my $extra = $opts{e} || 0; # true to remove additional information, such as the camera name
  21. my $all = $opts{a} || 0; # true to remove all tags
  22. my $batch_size = 100; # how many files to process at once
  23. my $image_re = qr/\.(png|jpe?g)\z/i;
  24. sub strip_tags ($files) {
  25. say ":: Stripping tracking tags of ", scalar(@$files), " photos...";
  26. say ":: The first image is: $files->[0]";
  27. system(
  28. "exiftool",
  29. "-overwrite_original_in_place", # overwrite image in place
  30. "-*Serial*Number*=", # remove serial number of camera photo
  31. "-*ImageUniqueID*=", # remove the unique image ID
  32. "-*Copyright*=", # remove copyright data
  33. "-usercomment=", # remove any user comment
  34. "-iptc=", # remove any IPTC data
  35. "-xmp=", # remove any XMP data
  36. "-geotag=", # remove geotag data
  37. "-gps:all=", # remove ALL GPS data
  38. (
  39. $extra
  40. ? (
  41. "-make=", # remove the brand name of the camera used to make the photo
  42. "-model=", # remove the model name of the camera used to make the photo
  43. "-software=", # remove the software name used to edit/process the photo
  44. "-imagedescription=", # remove any image description
  45. )
  46. : ()
  47. ),
  48. ($all ? ("-all=") : ()),
  49. @$files
  50. );
  51. }
  52. my @files;
  53. @ARGV or die "usage: perl script.pl -[ea] [dirs | files]\n";
  54. find(
  55. {
  56. no_chdir => 1,
  57. wanted => sub {
  58. if (/$image_re/ and -f $_) {
  59. push @files, $_;
  60. if (@files >= $batch_size) {
  61. strip_tags(\@files);
  62. @files = ();
  63. }
  64. }
  65. }
  66. } => @ARGV
  67. );
  68. if (@files) {
  69. strip_tags(\@files);
  70. }
  71. say ":: Done!";