From a21b7fd9583ccf8df2dd76cecefe34de184a1213 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 26 Oct 2019 12:56:41 +0100 Subject: [PATCH] Handle failure to open image --- media.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/media.py b/media.py index 7f16faa3..0ca9dc93 100644 --- a/media.py +++ b/media.py @@ -19,10 +19,14 @@ from shutil import copyfile from shutil import rmtree from shutil import move -def removeMetaData(imageFilename: str,outputFilename: str): +def removeMetaData(imageFilename: str,outputFilename: str) -> None: imageFile = open(imageFilename) image = Image.open(imageFilename) + if not image: + return data = list(image.getdata()) + if not data: + return imageWithoutExif = Image.new(image.mode, image.size) imageWithoutExif.putdata(data) imageWithoutExif.save(outputFilename)