Created
June 28, 2020 22:46
-
-
Save isaidnocookies/b47b1ee50493f79eb48d344f48c4d6eb to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python3 | |
# Uses the Python Imaging Library | |
# `pip install Pillow` works too | |
from PIL import Image | |
import glob | |
import os | |
import sys | |
def stripExifData(filename): | |
image = Image.open(filename) | |
image_data = list(image.getdata()) | |
image_without_exif = Image.new(image.mode, image.size) | |
image_without_exif.putdata(image_data) | |
image_without_exif.save(u"{}".format(filename)) | |
def stripAllExifFromDirectory(directory): | |
for root, dirs, files in os.walk(directory): | |
for file in files: | |
if file.endswith(".png") or file.endswith(".jpg") or file.endswith("jpeg"): | |
imageFilename = os.path.join(root, file) | |
try: | |
stripExifData(imageFilename) | |
print ("{} EXIF data was stripped!".format(imageFilename)) | |
except Exception as e: | |
print("Stripping process failed for: {} : {}".format(imageFilename, str(e))) | |
def main(): | |
if (len(sys.argv) < 2): | |
print ("Usage: {} [directory_to_strip]".format(sys.argv[0])) | |
quit() | |
stripAllExifFromDirectory(sys.argv[1]) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment