Created
April 25, 2019 23:56
-
-
Save flerpadoo/491c93073de20874194880eab7f931d5 to your computer and use it in GitHub Desktop.
Clears metadata from images and creates a backup of the file (saved with appended _original)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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