mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Changed module and codec names
This commit is contained in:
parent
799e8312cb
commit
98fa49ea37
|
@ -1,16 +1,19 @@
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
modules = {
|
modules = {
|
||||||
"PIL CORE": "PIL._imaging",
|
"pil": "PIL._imaging",
|
||||||
"TKINTER": "PIL._imagingtk",
|
"tkinter": "PIL._imagingtk",
|
||||||
"FREETYPE2": "PIL._imagingft",
|
"freetype2": "PIL._imagingft",
|
||||||
"LITTLECMS2": "PIL._imagingcms",
|
"littlecms2": "PIL._imagingcms",
|
||||||
"WEBP": "PIL._webp",
|
"webp": "PIL._webp",
|
||||||
"Transparent WEBP": ("WEBP", "WebPDecoderBuggyAlpha")
|
"transp_webp": ("WEBP", "WebPDecoderBuggyAlpha")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def check_module(feature):
|
def check_module(feature):
|
||||||
|
if feature not in modules:
|
||||||
|
raise ValueError("Unknown module %s" % feature)
|
||||||
|
|
||||||
module = modules[feature]
|
module = modules[feature]
|
||||||
|
|
||||||
method_to_call = None
|
method_to_call = None
|
||||||
|
@ -34,38 +37,31 @@ def check_module(feature):
|
||||||
|
|
||||||
def get_supported_modules():
|
def get_supported_modules():
|
||||||
supported_modules = []
|
supported_modules = []
|
||||||
for feature in get_all_modules():
|
for feature in modules:
|
||||||
if check_module(feature):
|
if check_module(feature):
|
||||||
supported_modules.append(feature)
|
supported_modules.append(feature)
|
||||||
return supported_modules
|
return supported_modules
|
||||||
|
|
||||||
|
|
||||||
def get_all_modules():
|
|
||||||
# While the dictionary keys could be used here,
|
|
||||||
# a static list is used to maintain order
|
|
||||||
return ["PIL CORE", "TKINTER", "FREETYPE2",
|
|
||||||
"LITTLECMS2", "WEBP", "Transparent WEBP"]
|
|
||||||
|
|
||||||
codecs = {
|
codecs = {
|
||||||
"JPEG": "jpeg",
|
"jpg": "jpeg",
|
||||||
"JPEG 2000": "jpeg2k",
|
"jpg_2000": "jpeg2k",
|
||||||
"ZLIB (PNG/ZIP)": "zip",
|
"zlib": "zip",
|
||||||
"LIBTIFF": "libtiff"
|
"libtiff": "libtiff"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def check_codec(feature):
|
def check_codec(feature):
|
||||||
|
if feature not in codecs:
|
||||||
|
raise ValueError("Unknown codec %s" % feature)
|
||||||
|
|
||||||
codec = codecs[feature]
|
codec = codecs[feature]
|
||||||
|
|
||||||
return codec + "_encoder" in dir(Image.core)
|
return codec + "_encoder" in dir(Image.core)
|
||||||
|
|
||||||
|
|
||||||
def get_supported_codecs():
|
def get_supported_codecs():
|
||||||
supported_codecs = []
|
supported_codecs = []
|
||||||
for feature in get_all_codecs():
|
for feature in codecs:
|
||||||
if check_codec(feature):
|
if check_codec(feature):
|
||||||
supported_codecs.append(feature)
|
supported_codecs.append(feature)
|
||||||
return supported_codecs
|
return supported_codecs
|
||||||
|
|
||||||
|
|
||||||
def get_all_codecs():
|
|
||||||
return ["JPEG", "JPEG 2000", "ZLIB (PNG/ZIP)", "LIBTIFF"]
|
|
||||||
|
|
20
selftest.py
20
selftest.py
|
@ -174,8 +174,15 @@ if __name__ == "__main__":
|
||||||
print("Python modules loaded from", os.path.dirname(Image.__file__))
|
print("Python modules loaded from", os.path.dirname(Image.__file__))
|
||||||
print("Binary modules loaded from", os.path.dirname(Image.core.__file__))
|
print("Binary modules loaded from", os.path.dirname(Image.core.__file__))
|
||||||
print("-"*68)
|
print("-"*68)
|
||||||
for feature in features.get_all_modules():
|
for name, feature in [
|
||||||
supported = features.check_module(feature)
|
("pil", "PIL CORE"),
|
||||||
|
("tkinter", "TKINTER"),
|
||||||
|
("freetype2", "FREETYPE2"),
|
||||||
|
("littlecms2", "LITTLECMS2"),
|
||||||
|
("webp", "WEBP"),
|
||||||
|
("transp_webp", "Transparent WEBP")
|
||||||
|
]:
|
||||||
|
supported = features.check_module(name)
|
||||||
|
|
||||||
if supported is None:
|
if supported is None:
|
||||||
# A method was being tested, but the module required
|
# A method was being tested, but the module required
|
||||||
|
@ -185,8 +192,13 @@ if __name__ == "__main__":
|
||||||
print("---", feature, "support ok")
|
print("---", feature, "support ok")
|
||||||
else:
|
else:
|
||||||
print("***", feature, "support not installed")
|
print("***", feature, "support not installed")
|
||||||
for feature in features.get_all_codecs():
|
for name, feature in [
|
||||||
if features.check_codec(feature):
|
("jpg", "JPEG"),
|
||||||
|
("jpg_2000", "JPEG 2000"),
|
||||||
|
("zlib", "ZLIB (PNG/ZIP)"),
|
||||||
|
("libtiff", "LIBTIFF")
|
||||||
|
]:
|
||||||
|
if features.check_codec(name):
|
||||||
print("---", feature, "support ok")
|
print("---", feature, "support ok")
|
||||||
else:
|
else:
|
||||||
print("***", feature, "support not installed")
|
print("***", feature, "support not installed")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user