Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python strip all GPS metadata from image

Is there a simple way, on windows and linux (Ubuntu Linux and Windows 7, both 64-bit with Python 2.7), to strip all (not just EXIF) GPS metadata on all images in a directory, and leave the rest of the metadata intact? It only needs to work for JPGs and PNGs.

like image 469
glen3b Avatar asked Jan 01 '26 05:01

glen3b


1 Answers

It's not exactly what I want, but I wrote a script using PyExiv2 which obscures some GPS EXIF data. Here is the script.

#!/usr/bin/python2.7
from pyexiv2 import ImageMetadata, ExifTag
from fractions import Fraction
import argparse, os
parser = argparse.ArgumentParser(description='Strip GPS metadata.')
parser.add_argument('dir', metavar='DIRECTORY',
                   help='The directory to process.')
args = parser.parse_args()
files = os.listdir(args.dir)
for tiname in files:
        iname = args.dir+tiname
        image = ImageMetadata(iname)
        image.read()
        image["Exif.GPSInfo.GPSLatitude"] = Fraction(1,1)
        image["Exif.GPSInfo.GPSLongitude"] = Fraction(1,1)
        image.write()

EDIT: This apparently (at least on windows) does not strip the latitude and longitude.

like image 99
glen3b Avatar answered Jan 05 '26 06:01

glen3b



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!