Last active
October 8, 2022 18:44
-
-
Save Tanimodori/66336dc8d2eb945711d2ec85beb6438f to your computer and use it in GitHub Desktop.
Using Python to Verify Image Integrity
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/python | |
# -*- coding: utf-8 -*- | |
import os | |
import re | |
import glob | |
from PIL import Image | |
my_path = "./" | |
files = glob.glob(my_path + "/**/*.*", recursive=True) | |
for filename in filter(re.compile(r".*\.(jpg|png|gif)").match, files): | |
try: | |
img = Image.open(filename) | |
img.verify() | |
except (IOError, SyntaxError) as e: | |
print("Bad file: " + filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment