diff options
author | Matthias Baumgartner <dev@igsor.net> | 2023-01-16 21:37:09 +0100 |
---|---|---|
committer | Matthias Baumgartner <dev@igsor.net> | 2023-01-16 21:37:09 +0100 |
commit | 05a841215c82ef40d4679dfc4d2c26572bd4d349 (patch) | |
tree | 9888ae0bd2345816d1ab479dd34b4c6b902c158a /bsie/reader/image/_pillow.py | |
parent | 057e09d6537bf5c39815661a75819081e3e5fda7 (diff) | |
parent | 58aaa864f9747d27c065739256d4c6635ca9b751 (diff) | |
download | bsie-05a841215c82ef40d4679dfc4d2c26572bd4d349.tar.gz bsie-05a841215c82ef40d4679dfc4d2c26572bd4d349.tar.bz2 bsie-05a841215c82ef40d4679dfc4d2c26572bd4d349.zip |
Merge branch 'mb/feature' into develop
Diffstat (limited to 'bsie/reader/image/_pillow.py')
-rw-r--r-- | bsie/reader/image/_pillow.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/bsie/reader/image/_pillow.py b/bsie/reader/image/_pillow.py new file mode 100644 index 0000000..3144509 --- /dev/null +++ b/bsie/reader/image/_pillow.py @@ -0,0 +1,39 @@ +""" + +Part of the bsie module. +A copy of the license is provided with the project. +Author: Matthias Baumgartner, 2022 +""" +# standard imports +import typing + +# external imports +import PIL.Image + +# bsie imports +from bsie.utils import errors + +# inner-module imports +from .. import base + +# exports +__all__: typing.Sequence[str] = ( + 'PillowImage', + ) + + +## code ## + +class PillowImage(base.Reader): + """Use PIL to read content of a variety of image file types.""" + + def __call__(self, path: str) -> PIL.Image: + try: + # open file with PIL + return PIL.Image.open(path) + except PIL.UnidentifiedImageError as err: + raise errors.UnsupportedFileFormatError(path) from err + except IOError as err: + raise errors.ReaderError(path) from err + +# EOF ## |