Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clears metadata from images and creates a backup of the file (saved with appended _original)
import magic, os, shutil
from gi.repository import GExiv2
def createBackupFile(filePath):
if os.path.isfile(filePath):
shutil.copyfile(filePath, filePath + "_original")
def wipeImageMetadata(filePath):
exif = GExiv2.Metadata(filePath)
try:
exif.delete_gps_info()
print("Cleared GPS data")
except:
print("No GPS data to clear")
try:
exif.erase_exif_thumbnail()
print("Cleared thumbnail data")
except:
print("No thumbnail to clear")
if exif.has_exif():
exif.clear_exif()
print("Cleared exif data")
if exif.has_iptc():
print("Cleared IPTC data")
exif.clear_iptc()
if exif.has_xmp():
print("Cleared XMP data")
exif.clear_xmp()
exif.save_file(filePath)
def checkFileType(filePath):
fileTypeProp = magic.from_file(filePath, mime = True)
print(fileTypeProp)
def main():
createBackupFile(filePath)
wipeImageMetadata(filePath)
if __name__ == "__main__":
global filePath
filePath = '/path/to/images'
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.