import collections import os import sys import warnings import PIL from . import Image modules = { "pil": ("PIL._imaging", "PILLOW_VERSION"), "tkinter": ("PIL._tkinter_finder", None), "freetype2": ("PIL._imagingft", "freetype2_version"), "littlecms2": ("PIL._imagingcms", "littlecms_version"), "webp": ("PIL._webp", "webpdecoder_version"), } def check_module(feature): """ Checks if a module is available. :param feature: The module to check for. :returns: ``True`` if available, ``False`` otherwise. :raises ValueError: If the module is not defined in this version of Pillow. """ if not (feature in modules): raise ValueError(f"Unknown module {feature}") module, ver = modules[feature] try: __import__(module) return True except ImportError: return False def version_module(feature): """ :param feature: The module to check for. :returns: The loaded version number as a string, or ``None`` if unknown or not available. :raises ValueError: If the module is not defined in this version of Pillow. """ if not check_module(feature): return None module, ver = modules[feature] if ver is None: return None return getattr(__import__(module, fromlist=[ver]), ver) def get_supported_modules(): """ :returns: A list of all supported modules. """ return [f for f in modules if check_module(f)] codecs = { "jpg": ("jpeg", "jpeglib"), "jpg_2000": ("jpeg2k", "jp2klib"), "zlib": ("zip", "zlib"), "libtiff": ("libtiff", "libtiff"), } def check_codec(feature): """ Checks if a codec is available. :param feature: The codec to check for. :returns: ``True`` if available, ``False`` otherwise. :raises ValueError: If the codec is not defined in this version of Pillow. """ if feature not in codecs: raise ValueError(f"Unknown codec {feature}") codec, lib = codecs[feature] return codec + "_encoder" in dir(Image.core) def version_codec(feature): """ :param feature: The codec to check for. :returns: The version number as a string, or ``None`` if not available. Checked at compile time for ``jpg``, run-time otherwise. :raises ValueError: If the codec is not defined in this version of Pillow. """ if not check_codec(feature): return None codec, lib = codecs[feature] version = getattr(Image.core, lib + "_version") if feature == "libtiff": return version.split("\n")[0].split("Version ")[1] return version def get_supported_codecs(): """ :returns: A list of all supported codecs. """ return [f for f in codecs if check_codec(f)] features = { "webp_anim": ("PIL._webp", "HAVE_WEBPANIM", None), "webp_mux": ("PIL._webp", "HAVE_WEBPMUX", None), "transp_webp": ("PIL._webp", "HAVE_TRANSPARENCY", None), "raqm": ("PIL._imagingft", "HAVE_RAQM", "raqm_version"), "libjpeg_turbo": ("PIL._imaging", "HAVE_LIBJPEGTURBO", "libjpeg_turbo_version"), "libimagequant": ("PIL._imaging", "HAVE_LIBIMAGEQUANT", "imagequant_version"), "xcb": ("PIL._imaging", "HAVE_XCB", None), } def check_feature(feature): """ Checks if a feature is available. :param feature: The feature to check for. :returns: ``True`` if available, ``False`` if unavailable, ``None`` if unknown. :raises ValueError: If the feature is not defined in this version of Pillow. """ if feature not in features: raise ValueError(f"Unknown feature {feature}") module, flag, ver = features[feature] try: imported_module = __import__(module, fromlist=["PIL"]) return getattr(imported_module, flag) except ImportError: return None def version_feature(feature): """ :param feature: The feature to check for. :returns: The version number as a string, or ``None`` if not available. :raises ValueError: If the feature is not defined in this version of Pillow. """ if not check_feature(feature): return None module, flag, ver = features[feature] if ver is None: return None return getattr(__import__(module, fromlist=[ver]), ver) def get_supported_features(): """ :returns: A list of all supported features. """ return [f for f in features if check_feature(f)] def check(feature): """ :param feature: A module, codec, or feature name. :returns: ``True`` if the module, codec, or feature is available, ``False`` or ``None`` otherwise. """ if feature in modules: return check_module(feature) if feature in codecs: return check_codec(feature) if feature in features: return check_feature(feature) warnings.warn(f"Unknown feature '{feature}'.", stacklevel=2) return False def version(feature): """ :param feature: The module, codec, or feature to check for. :returns: The version number as a string, or ``None`` if unknown or not available. """ if feature in modules: return version_module(feature) if feature in codecs: return version_codec(feature) if feature in features: return version_feature(feature) return None def get_supported(): """ :returns: A list of all supported modules, features, and codecs. """ ret = get_supported_modules() ret.extend(get_supported_features()) ret.extend(get_supported_codecs()) return ret def pilinfo(out=None, supported_formats=True): """ Prints information about this installation of Pillow. This function can be called with ``python -m PIL``. :param out: The output stream to print to. Defaults to ``sys.stdout`` if ``None``. :param supported_formats: If ``True``, a list of all supported image file formats will be printed. """ if out is None: out = sys.stdout Image.init() print("-" * 68, file=out) print(f"Pillow {PIL.__version__}", file=out) py_version = sys.version.splitlines() print(f"Python {py_version[0].strip()}", file=out) for py_version in py_version[1:]: print(f" {py_version.strip()}", file=out) print("-" * 68, file=out) print( f"Python modules loaded from {os.path.dirname(Image.__file__)}", file=out, ) print( f"Binary modules loaded from {os.path.dirname(Image.core.__file__)}", file=out, ) print("-" * 68, file=out) for name, feature in [ ("pil", "PIL CORE"), ("tkinter", "TKINTER"), ("freetype2", "FREETYPE2"), ("littlecms2", "LITTLECMS2"), ("webp", "WEBP"), ("transp_webp", "WEBP Transparency"), ("webp_mux", "WEBPMUX"), ("webp_anim", "WEBP Animation"), ("jpg", "JPEG"), ("jpg_2000", "OPENJPEG (JPEG2000)"), ("zlib", "ZLIB (PNG/ZIP)"), ("libtiff", "LIBTIFF"), ("raqm", "RAQM (Bidirectional Text)"), ("libimagequant", "LIBIMAGEQUANT (Quantization method)"), ("xcb", "XCB (X protocol)"), ]: if check(name): if name == "jpg" and check_feature("libjpeg_turbo"): v = "libjpeg-turbo " + version_feature("libjpeg_turbo") else: v = version(name) if v is not None: version_static = name in ("pil", "jpg") if name == "littlecms2": # this check is also in src/_imagingcms.c:setup_module() version_static = tuple(int(x) for x in v.split(".")) < (2, 7) t = "compiled for" if version_static else "loaded" print("---", feature, "support ok,", t, v, file=out) else: print("---", feature, "support ok", file=out) else: print("***", feature, "support not installed", file=out) print("-" * 68, file=out) if supported_formats: extensions = collections.defaultdict(list) for ext, i in Image.EXTENSION.items(): extensions[i].append(ext) for i in sorted(Image.ID): line = f"{i}" if i in Image.MIME: line = f"{line} {Image.MIME[i]}" print(line, file=out) if i in extensions: print( "Extensions: {}".format(", ".join(sorted(extensions[i]))), file=out ) features = [] if i in Image.OPEN: features.append("open") if i in Image.SAVE: features.append("save") if i in Image.SAVE_ALL: features.append("save_all") if i in Image.DECODERS: features.append("decode") if i in Image.ENCODERS: features.append("encode") print("Features: {}".format(", ".join(features)), file=out) print("-" * 68, file=out)
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
__pycache__ | Folder | 2755 |
|
|
BdfFontFile.py | File | 2.75 KB | 0644 |
|
BlpImagePlugin.py | File | 14 KB | 0644 |
|
BmpImagePlugin.py | File | 13.92 KB | 0644 |
|
BufrStubImagePlugin.py | File | 1.48 KB | 0644 |
|
ContainerIO.py | File | 2.82 KB | 0644 |
|
CurImagePlugin.py | File | 1.68 KB | 0644 |
|
DcxImagePlugin.py | File | 2.09 KB | 0644 |
|
DdsImagePlugin.py | File | 5.34 KB | 0644 |
|
EpsImagePlugin.py | File | 11.82 KB | 0644 |
|
ExifTags.py | File | 8.8 KB | 0644 |
|
FitsStubImagePlugin.py | File | 1.59 KB | 0644 |
|
FliImagePlugin.py | File | 4.23 KB | 0644 |
|
FontFile.py | File | 2.7 KB | 0644 |
|
FpxImagePlugin.py | File | 6.53 KB | 0644 |
|
FtexImagePlugin.py | File | 3.23 KB | 0644 |
|
GbrImagePlugin.py | File | 2.73 KB | 0644 |
|
GdImageFile.py | File | 2.47 KB | 0644 |
|
GifImagePlugin.py | File | 28.25 KB | 0644 |
|
GimpGradientFile.py | File | 3.27 KB | 0644 |
|
GimpPaletteFile.py | File | 1.24 KB | 0644 |
|
GribStubImagePlugin.py | File | 1.51 KB | 0644 |
|
Hdf5StubImagePlugin.py | File | 1.48 KB | 0644 |
|
IcnsImagePlugin.py | File | 11.44 KB | 0644 |
|
IcoImagePlugin.py | File | 9.94 KB | 0644 |
|
ImImagePlugin.py | File | 10.53 KB | 0644 |
|
Image.py | File | 113.4 KB | 0644 |
|
ImageChops.py | File | 7.13 KB | 0644 |
|
ImageCms.py | File | 36.22 KB | 0644 |
|
ImageColor.py | File | 8.44 KB | 0644 |
|
ImageDraw.py | File | 29.94 KB | 0644 |
|
ImageDraw2.py | File | 4.9 KB | 0644 |
|
ImageEnhance.py | File | 3.12 KB | 0644 |
|
ImageFile.py | File | 20.74 KB | 0644 |
|
ImageFilter.py | File | 15.46 KB | 0644 |
|
ImageFont.py | File | 43.49 KB | 0644 |
|
ImageGrab.py | File | 3.54 KB | 0644 |
|
ImageMath.py | File | 6.88 KB | 0644 |
|
ImageMode.py | File | 1.6 KB | 0644 |
|
ImageMorph.py | File | 7.67 KB | 0644 |
|
ImageOps.py | File | 18.03 KB | 0644 |
|
ImagePalette.py | File | 6.2 KB | 0644 |
|
ImagePath.py | File | 336 B | 0644 |
|
ImageQt.py | File | 5.67 KB | 0644 |
|
ImageSequence.py | File | 1.81 KB | 0644 |
|
ImageShow.py | File | 6.15 KB | 0644 |
|
ImageStat.py | File | 3.81 KB | 0644 |
|
ImageTk.py | File | 9.11 KB | 0644 |
|
ImageTransform.py | File | 2.78 KB | 0644 |
|
ImageWin.py | File | 7.02 KB | 0644 |
|
ImtImagePlugin.py | File | 2.15 KB | 0644 |
|
IptcImagePlugin.py | File | 5.6 KB | 0644 |
|
Jpeg2KImagePlugin.py | File | 8.52 KB | 0644 |
|
JpegImagePlugin.py | File | 27.16 KB | 0644 |
|
JpegPresets.py | File | 12.41 KB | 0644 |
|
McIdasImagePlugin.py | File | 1.71 KB | 0644 |
|
MicImagePlugin.py | File | 2.54 KB | 0644 |
|
MpegImagePlugin.py | File | 1.76 KB | 0644 |
|
MpoImagePlugin.py | File | 4.14 KB | 0644 |
|
MspImagePlugin.py | File | 5.43 KB | 0644 |
|
PSDraw.py | File | 6.51 KB | 0644 |
|
PaletteFile.py | File | 1.08 KB | 0644 |
|
PalmImagePlugin.py | File | 8.89 KB | 0644 |
|
PcdImagePlugin.py | File | 1.47 KB | 0644 |
|
PcfFontFile.py | File | 6.2 KB | 0644 |
|
PcxImagePlugin.py | File | 5.41 KB | 0644 |
|
PdfImagePlugin.py | File | 7.49 KB | 0644 |
|
PdfParser.py | File | 33.58 KB | 0644 |
|
PixarImagePlugin.py | File | 1.61 KB | 0644 |
|
PngImagePlugin.py | File | 42.79 KB | 0644 |
|
PpmImagePlugin.py | File | 4.34 KB | 0644 |
|
PsdImagePlugin.py | File | 7.56 KB | 0644 |
|
PyAccess.py | File | 9.37 KB | 0644 |
|
SgiImagePlugin.py | File | 5.96 KB | 0644 |
|
SpiderImagePlugin.py | File | 9.31 KB | 0644 |
|
SunImagePlugin.py | File | 4.2 KB | 0644 |
|
TarIO.py | File | 1.41 KB | 0644 |
|
TgaImagePlugin.py | File | 6.18 KB | 0644 |
|
TiffImagePlugin.py | File | 66.86 KB | 0644 |
|
TiffTags.py | File | 14.22 KB | 0644 |
|
WalImageFile.py | File | 5.4 KB | 0644 |
|
WebPImagePlugin.py | File | 10.54 KB | 0644 |
|
WmfImagePlugin.py | File | 4.56 KB | 0644 |
|
XVThumbImagePlugin.py | File | 1.9 KB | 0644 |
|
XbmImagePlugin.py | File | 2.37 KB | 0644 |
|
XpmImagePlugin.py | File | 3 KB | 0644 |
|
__init__.py | File | 3.18 KB | 0644 |
|
__main__.py | File | 41 B | 0644 |
|
_binary.py | File | 1.75 KB | 0644 |
|
_imaging.cpython-36m-x86_64-linux-gnu.so | File | 650.13 KB | 0755 |
|
_imagingcms.cpython-36m-x86_64-linux-gnu.so | File | 38.05 KB | 0755 |
|
_imagingft.cpython-36m-x86_64-linux-gnu.so | File | 41.98 KB | 0755 |
|
_imagingmath.cpython-36m-x86_64-linux-gnu.so | File | 24.43 KB | 0755 |
|
_imagingmorph.cpython-36m-x86_64-linux-gnu.so | File | 8.12 KB | 0755 |
|
_imagingtk.cpython-36m-x86_64-linux-gnu.so | File | 9.37 KB | 0755 |
|
_tkinter_finder.py | File | 224 B | 0644 |
|
_util.py | File | 359 B | 0644 |
|
_version.py | File | 50 B | 0644 |
|
_webp.cpython-36m-x86_64-linux-gnu.so | File | 40.82 KB | 0755 |
|
features.py | File | 8.8 KB | 0644 |
|