Skip to content

Instantly share code, notes, and snippets.

@Tanimodori
Last active October 8, 2022 18:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tanimodori/66336dc8d2eb945711d2ec85beb6438f to your computer and use it in GitHub Desktop.
Save Tanimodori/66336dc8d2eb945711d2ec85beb6438f to your computer and use it in GitHub Desktop.
Using Python to Verify Image Integrity
#!/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