Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/galaxy/util/image_util.py @ 5:9b1c78e6ba9c draft default tip
"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
| author | shellac |
|---|---|
| date | Mon, 01 Jun 2020 08:59:25 -0400 |
| parents | 79f47841a781 |
| children |
comparison
equal
deleted
inserted
replaced
| 4:79f47841a781 | 5:9b1c78e6ba9c |
|---|---|
| 1 """Provides utilities for working with image files.""" | |
| 2 from __future__ import absolute_import | |
| 3 | |
| 4 import imghdr | |
| 5 import logging | |
| 6 | |
| 7 try: | |
| 8 import Image as PIL | |
| 9 except ImportError: | |
| 10 try: | |
| 11 from PIL import Image as PIL | |
| 12 except ImportError: | |
| 13 PIL = None | |
| 14 | |
| 15 log = logging.getLogger(__name__) | |
| 16 | |
| 17 | |
| 18 def image_type(filename): | |
| 19 fmt = None | |
| 20 if PIL is not None: | |
| 21 try: | |
| 22 im = PIL.open(filename) | |
| 23 fmt = im.format | |
| 24 im.close() | |
| 25 except Exception: | |
| 26 # We continue to try with imghdr, so this is a rare case of an | |
| 27 # exception we expect to happen frequently, so we're not logging | |
| 28 pass | |
| 29 if not fmt: | |
| 30 fmt = imghdr.what(filename) | |
| 31 if fmt: | |
| 32 return fmt.upper() | |
| 33 else: | |
| 34 return False | |
| 35 | |
| 36 | |
| 37 def check_image_type(filename, types): | |
| 38 fmt = image_type(filename) | |
| 39 if fmt in types: | |
| 40 return True | |
| 41 return False |
