hydrus/hydrus/core/images/HydrusImageOpening.py

24 lines
642 B
Python
Raw Normal View History

2023-10-18 20:31:50 +00:00
import typing
2023-10-04 20:51:17 +00:00
from PIL import Image as PILImage
from hydrus.core import HydrusExceptions
2023-10-18 20:31:50 +00:00
def RawOpenPILImage( path: typing.Union[ str, typing.BinaryIO ] ) -> PILImage.Image:
2023-10-04 20:51:17 +00:00
try:
pil_image = PILImage.open( path )
except Exception as e:
2023-11-29 22:27:53 +00:00
raise HydrusExceptions.DamagedOrUnusualFileException( f'Could not load the image at "{path}"--it was likely malformed!' ) from e
if pil_image is None:
raise HydrusExceptions.DamagedOrUnusualFileException( f'Could not load the image at "{path}"--it was likely malformed!' )
2023-10-04 20:51:17 +00:00
return pil_image