Created
November 17, 2020 12:46
-
-
Save henriklied/a57246690f8ed761baf9004c1a65d63e to your computer and use it in GitHub Desktop.
Strip Exif data from png and jpg files
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/env python3 | |
from PIL import Image | |
import os, sys, glob | |
cwd = os.getcwd() | |
if len(sys.argv) > 1: | |
cwd = sys.argv[1] | |
files = glob.glob(os.path.join(cwd, '*.jpg')) | |
files.extend(glob.glob(os.path.join(cwd, '*.png'))) | |
if not os.path.exists(os.path.join(cwd, 'cleaned_images')): | |
os.makedirs(os.path.join(cwd, 'cleaned_images')) | |
print(files) | |
for image in files: | |
image_name = image.split('/')[-1] | |
print("Reading", image_name) | |
im = Image.open(image) | |
im_data = list(im.getdata()) | |
cleaned_image = Image.new(im.mode, im.size) | |
cleaned_image.putdata(im_data) | |
cleaned_image.save(os.path.join(cwd, 'cleaned_images', image_name)) | |
print("Saved %s to cleaned_images/%s" % (image, os.path.join(cwd, 'cleaned_images', image_name))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment