Skip to content

Instantly share code, notes, and snippets.

@jayliew
Last active September 30, 2016 22:42
Show Gist options
  • Save jayliew/2b064908d8ec5e0e075fde95929a8dab to your computer and use it in GitHub Desktop.
Save jayliew/2b064908d8ec5e0e075fde95929a8dab to your computer and use it in GitHub Desktop.
Python script to remove geographic coordinates / latitude (lat) + longitude (long) EXIF data from JPG / JPEG photos / pictures / pics
#!/usr/bin/env python
#
# Purpose: This script strips out all the geo latitude + longitude data
# from JPG / JPEG files
#
# Installation: Make sure you have PIL (Python Imaging Library), or "Pillow"
#
# Usage: Put this file in directory with photos and run it from there
#
# e.g.
# cd /some/dir/with/photos
# python exif_stripper.py
#
# Jay Liew, Sept 2016
from PIL import Image
from os import listdir
from os.path import isfile, join
import re
mypath = "."
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
for fn in onlyfiles:
pattern = r'^[^.]\w*\.jpe?g$'
r = re.compile(pattern, re.IGNORECASE)
if r.findall(fn):
print "Stripping " + fn
image_file = open(fn)
image = Image.open(image_file)
data = list(image.getdata())
image_without_exif = Image.new(image.mode, image.size)
image_without_exif.putdata(data)
image_without_exif.save( "SAFE_" + fn)
print "Success! SAFE_" + fn
else:
print "Leaving alone: " + fn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment