Improve error handling in aspect_ratio()
This commit is contained in:
parent
ede29cbc95
commit
7c2fdd6d5a
@ -165,11 +165,10 @@ def aspect_ratio(image_src):
|
|||||||
image = Image.open(image_src)
|
image = Image.open(image_src)
|
||||||
if image.width > 0 and image.height > 0:
|
if image.width > 0 and image.height > 0:
|
||||||
return image.width / image.height
|
return image.width / image.height
|
||||||
print(f'aspect_ratio(): image size is {image.width} x {image.height}')
|
print(f'aspect_ratio(): Invalid image size {image.width} x {image.height}')
|
||||||
except ModuleNotFoundError as error:
|
# ModuleNotFoundError and FileNotFoundError are the most expected, but all are handled equally.
|
||||||
print(f'aspect_ratio(): {error}')
|
except Exception as error:
|
||||||
except FileNotFoundError as error:
|
print(f'aspect_ratio(): {type(error).__name__}: {error}')
|
||||||
print(f'aspect_ratio(): {error}')
|
|
||||||
return 1 # Assume 1:1 when unable to read actual image size
|
return 1 # Assume 1:1 when unable to read actual image size
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user