Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/galaxy/util/image_util.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author | shellac |
---|---|
date | Sat, 02 May 2020 07:14:21 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:26e78fe6e8c4 |
---|---|
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 |