Everytime you take a picture fo something, there is metadata data that is included in the file. Sometimes the data is fairly innocent and includes focal length, camera model, time of picture, etc. However somtimes, it can be used to identify the owner of the camera, the GPS location, and other data that would otherwise be undesirable to people you don’t know.

This is a huge risk when it comes to putting content online. It would be a bit concerning if the picture of the bird in your backyard ended up revealing where your house is.

Even more so you could be taking a picture doing something completely non-descript by taking a picture of your vehicle to show off:

Photo by DON JACKSON-WYATT

The exif data contained:

GPS Latitude                    : 41.88751364147307
GPS Longitude                   : -87.64238256265014

The next thing you know someone is knocking at your door demanding that you pay your “helicopter tax.” Yea, I also thought this was America.

How do you see this data?

On Linux the exiftool makes it easy to view this.

Install it under arch with: sudo pacman -S perl-image-exiftool

To run the command on a file: exiftool <file> and it’ll spit out an table that looks like:

$ exiftool PXL_20240330_182225063.jpg
ExifTool Version Number         : 12.92
File Name                       : PXL_20240330_182225063.jpg
Directory                       : .
File Size                       : 4.6 MB
File Modification Date/Time     : 2024:04:24 15:06:03-05:00
File Access Date/Time           : 2024:08:08 23:39:41-05:00
File Inode Change Date/Time     : 2024:04:24 15:06:03-05:00
File Permissions                : -rw-r--r--
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
Exif Byte Order                 : Little-endian (Intel, II)
Make                            : Banana
Camera Model Name               : Phone 5
Orientation                     : Horizontal (normal)
X Resolution                    : 72
Y Resolution                    : 72
Resolution Unit                 : inches
Software                        : HDR+ 1.0.611900660zd
Modify Date                     : 2024:03:30 14:22:25

To strip out all the metadata use the --ALL= option before specifying the input files.

There are more options to eliminate just the GPS data, or modifying the dates. For examples of this see the online man page

Ok, so how would we automate this?

Good question, even better question is: How would we get pre-commit to do this for us? After all we don’t want that data to sneak into a production environment through our code repository.

The developer on github stefmolin has made a small Python based EXIF data remover as a pre-commit hook. It doesn’t look as full featured as the exif-tool, but it does remove all of the EXIF data from all of the images that are being commited. I created a few issues to give more configurability. I hope they get considered.

The Repository of this precommit hook is: https://github.com/stefmolin/exif-stripper

To add the hook to your .pre-commit-config.yaml:

- repo: https://github.com/stefmolin/exif-stripper
  rev: 0.3.1
  hooks:
    - id: strip-exif