2017-01-17 16:22:18 +03:00
|
|
|
from . import Image
|
2015-05-14 12:43:28 +03:00
|
|
|
|
|
|
|
modules = {
|
2015-05-14 13:57:01 +03:00
|
|
|
"pil": "PIL._imaging",
|
|
|
|
"tkinter": "PIL._imagingtk",
|
|
|
|
"freetype2": "PIL._imagingft",
|
|
|
|
"littlecms2": "PIL._imagingcms",
|
|
|
|
"webp": "PIL._webp",
|
|
|
|
"transp_webp": ("WEBP", "WebPDecoderBuggyAlpha")
|
2015-05-14 12:43:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def check_module(feature):
|
2015-05-14 13:57:01 +03:00
|
|
|
if feature not in modules:
|
|
|
|
raise ValueError("Unknown module %s" % feature)
|
|
|
|
|
2015-05-14 12:43:28 +03:00
|
|
|
module = modules[feature]
|
|
|
|
|
|
|
|
method_to_call = None
|
2016-10-31 03:43:32 +03:00
|
|
|
if isinstance(module, tuple):
|
2015-05-14 12:43:28 +03:00
|
|
|
module, method_to_call = module
|
|
|
|
|
|
|
|
try:
|
|
|
|
imported_module = __import__(module)
|
|
|
|
except ImportError:
|
|
|
|
# If a method is being checked, None means that
|
|
|
|
# rather than the method failing, the module required for the method
|
|
|
|
# failed to be imported first
|
|
|
|
return None if method_to_call else False
|
|
|
|
|
|
|
|
if method_to_call:
|
|
|
|
method = getattr(imported_module, method_to_call)
|
|
|
|
return method() is True
|
|
|
|
else:
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
def get_supported_modules():
|
|
|
|
supported_modules = []
|
2015-05-14 13:57:01 +03:00
|
|
|
for feature in modules:
|
2015-05-14 12:43:28 +03:00
|
|
|
if check_module(feature):
|
|
|
|
supported_modules.append(feature)
|
|
|
|
return supported_modules
|
|
|
|
|
|
|
|
codecs = {
|
2015-05-14 13:57:01 +03:00
|
|
|
"jpg": "jpeg",
|
|
|
|
"jpg_2000": "jpeg2k",
|
|
|
|
"zlib": "zip",
|
|
|
|
"libtiff": "libtiff"
|
2015-05-14 12:43:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def check_codec(feature):
|
2015-05-14 13:57:01 +03:00
|
|
|
if feature not in codecs:
|
|
|
|
raise ValueError("Unknown codec %s" % feature)
|
|
|
|
|
2015-05-14 12:43:28 +03:00
|
|
|
codec = codecs[feature]
|
2015-05-14 13:57:01 +03:00
|
|
|
|
2015-05-14 12:43:28 +03:00
|
|
|
return codec + "_encoder" in dir(Image.core)
|
|
|
|
|
|
|
|
|
|
|
|
def get_supported_codecs():
|
|
|
|
supported_codecs = []
|
2015-05-14 13:57:01 +03:00
|
|
|
for feature in codecs:
|
2015-05-14 12:43:28 +03:00
|
|
|
if check_codec(feature):
|
|
|
|
supported_codecs.append(feature)
|
|
|
|
return supported_codecs
|