guetzli-recursively-gui/.eggs/py2app-0.12-py3.6.egg/py2app/recipes/PIL/prescript.py

44 lines
1.2 KiB
Python
Raw Normal View History

2017-04-20 00:57:59 +02:00
def _recipes_pil_prescript(plugins):
try:
import Image
have_PIL = False
except ImportError:
from PIL import Image
have_PIL = True
import sys
def init():
if Image._initialized >= 2:
return
if have_PIL:
try:
import PIL.JpegPresets
sys.modules['JpegPresets'] = PIL.JpegPresets
except ImportError:
pass
for plugin in plugins:
try:
if have_PIL:
try:
# First try absolute import through PIL (for Pillow support)
# only then try relative imports
m = __import__('PIL.' + plugin, globals(), locals(), [])
m = getattr(m, plugin)
sys.modules[plugin] = m
continue
except ImportError:
pass
__import__(plugin, globals(), locals(), [])
except ImportError:
if Image.DEBUG:
print('Image: failed to import')
if Image.OPEN or Image.SAVE:
Image._initialized = 2
return 1
Image.init = init