From f73e619c42e576e324bee6bf4df5faa8e4bac7dc Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Mon, 3 Jan 2022 20:38:11 -0300 Subject: [PATCH] Switch small image detection to square pixels only on PIL formats --- biostools/extractors.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/biostools/extractors.py b/biostools/extractors.py index d4cc5ee..e0e49c2 100644 --- a/biostools/extractors.py +++ b/biostools/extractors.py @@ -600,6 +600,11 @@ class ImageExtractor(Extractor): image = PIL.Image.open(io.BytesIO(file_data)) if not image: raise Exception('no image') + + # Don't save image if it's too small. + x, y = image.size + if (x * y) < 10000: + raise Exception('too small') except: return False @@ -629,11 +634,6 @@ class ImageExtractor(Extractor): # Save image to destination directory. image_path = os.path.join(dest_dir_0, 'image.png') try: - # Don't save image if it's too small. - x, y = image.size - if (x < 100 and y < 100) or x < 25 or y < 25: - raise Exception('too small') - image.save(image_path) return True except: