Use exiftool to strip EXIF data from shared images
As you may know, the image files you put "out there" on the Web may have info you don’t wish to make known, such as the exact model of the device that took the picture or, worse, the GPS coordinates of the location where you took the picture.
ExifTool by Phil Harvey is the command-line tool for manipulating EXIF data in image files:
It’s almost certainly available in your Linux or BSD distro’s repo if it’s not installed by default.
Like many powerfull CLI tools, it’s got a huge list of options in the man page. But you can get by with a small subset of its features.
To view EXIF data in an image:
$ exiftool concerned_beanz.png # ... # all file metadata and exif data shows here # ...
Or just the "Software" used to make the image:
$ exiftool -Software concerned_beanz.png Software : www.inkscape.org
To write the EXIF tag "Software":
$ exiftool -Software='Ratware 9000' concerned_beanz.png 1 image files updated $ exiftool -Software concerned_beanz.png Software : Ratware 9000
To delete the EXIF tag "Software":
$ exiftool -Software= concerned_beanz.png
To delete all optional EXIF tags from the image:
$ exiftool -all= concerned_beanz.png
Note that all of the above examples will also produce a copy of the file before it was altered:
$ ls concerned_beanz.png concerned_beanz.png_original
To strip EXIF data overwrite the original file without making a backup, add -overwrite_original_in_place
like so:
$ exiftool -all= concerned_beanz.png
Recurse directories, ignore directories
You can certainly write your own script around exiftool, or use it
in a fancy find
invocation. But I really appreciate that the tool
has directory traversal covered right out of the box.
Just add -r
to perform an action on all supported image and media files found
in a directory and subdirectories (as with many tools, "r" is for "recursive").
I just navigate to the directory I want and use .
for the current directory,
so stripping all tags looks like this:
$ exiftool -all= -r .
But I also want to skip a particular directory. Thankfully, that’s easy
with the -i
option ("i" is for "ignore"):
$ exiftool -all= -i repos -r .
Oh, and I also don’t want to have to go through and remove all of the
"_original" copies because I already have these backed up.
So I add the -overwrite_original_in_place
option.
Put it all together, and this stripped all of the unwanted EXIF data from my website:
$ exiftool -all= -overwrite_original_in_place -i repos -r .
Auto-strip new files
I can see which files are new by asking git
.
I’ve updated the rat
script that I use to manage this site
to have a new rat exif
sub-command.
Here’s the relevant part:
my $output = `git ls-files -o -m --exclude-standard`; my @files = split(/\n/, $output); my $fcount = @files; print "Site has $fcount changed files...\n"; foreach (@files) { if($_ =~ /\.(jpg|png)$/){ print "Found: $_\n"; print `exiftool -all= -overwrite_original_in_place "$_"` } } print "Done.\n";
Here’s something similar in shell (untested):
for f in $(git ls-files -o -m --exclude-standard | ag '(jpg|png)$') do exiftool -all= -overwrite_original_in_place "$f" done