Switch small image detection to square pixels only on PIL formats

This commit is contained in:
RichardG867
2022-01-03 20:38:11 -03:00
parent f2c71d2a1f
commit f73e619c42

View File

@@ -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: