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