Remove outdated fallback to 'import Image'

The fallback 'import Image' was added in commit
99621d7a01 for the PIL package. However,
the PIL package is no longer maintained and does not support Python 3.
Development has moved to the Pillow package which always installs to the
PIL namespace.

Pillow repo: https://github.com/python-pillow/Pillow
Old PIL website: http://www.pythonware.com/products/pil/
This commit is contained in:
Jon Dufresne 2019-01-06 08:32:48 -08:00
parent 353c3e9fd6
commit f1e41a616c
3 changed files with 14 additions and 19 deletions

View File

@ -1713,9 +1713,9 @@ the `Dublin Core metadata <http://dublincore.org/>`_.
This flag determines if sphinx should try to fix image formats that are not This flag determines if sphinx should try to fix image formats that are not
supported by some epub readers. At the moment palette images with a small supported by some epub readers. At the moment palette images with a small
color table are upgraded. You need the Python Image Library (Pillow the color table are upgraded. You need Pillow, the Python Image Library,
successor of the PIL) installed to use this option. The default value is installed to use this option. The default value is ``False`` because the
``False`` because the automatic conversion may lose information. automatic conversion may lose information.
.. versionadded:: 1.2 .. versionadded:: 1.2

View File

@ -28,9 +28,6 @@ from sphinx.util.osutil import ensuredir, copyfile
try: try:
from PIL import Image from PIL import Image
except ImportError:
try:
import Image
except ImportError: except ImportError:
Image = None Image = None
@ -401,9 +398,9 @@ class EpubBuilder(StandaloneHTMLBuilder):
def copy_image_files_pil(self): def copy_image_files_pil(self):
# type: () -> None # type: () -> None
"""Copy images using the PIL. """Copy images using Pillow, the Python Imaging Libary.
The method tries to read and write the files with the PIL, The method tries to read and write the files with Pillow, converting
converting the format and resizing the image if necessary/possible. the format and resizing the image if necessary/possible.
""" """
ensuredir(path.join(self.outdir, self.imagedir)) ensuredir(path.join(self.outdir, self.imagedir))
for src in status_iterator(self.images, 'copying images... ', "brown", for src in status_iterator(self.images, 'copying images... ', "brown",
@ -424,7 +421,8 @@ class EpubBuilder(StandaloneHTMLBuilder):
continue continue
if self.config.epub_fix_images: if self.config.epub_fix_images:
if img.mode in ('P',): if img.mode in ('P',):
# See PIL documentation for Image.convert() # See the Pillow documentation for Image.convert()
# https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.convert
img = img.convert() img = img.convert()
if self.config.epub_max_image_width > 0: if self.config.epub_max_image_width > 0:
(width, height) = img.size (width, height) = img.size
@ -441,12 +439,12 @@ class EpubBuilder(StandaloneHTMLBuilder):
def copy_image_files(self): def copy_image_files(self):
# type: () -> None # type: () -> None
"""Copy image files to destination directory. """Copy image files to destination directory.
This overwritten method can use the PIL to convert image files. This overwritten method can use Pillow to convert image files.
""" """
if self.images: if self.images:
if self.config.epub_fix_images or self.config.epub_max_image_width: if self.config.epub_fix_images or self.config.epub_max_image_width:
if not Image: if not Image:
logger.warning(__('PIL not found - copying image files')) logger.warning(__('Pillow not found - copying image files'))
super().copy_image_files() super().copy_image_files()
else: else:
self.copy_image_files_pil() self.copy_image_files_pil()

View File

@ -21,10 +21,7 @@ import imagesize
from sphinx.deprecation import RemovedInSphinx30Warning from sphinx.deprecation import RemovedInSphinx30Warning
try: try:
from PIL import Image # check for the Python Imaging Library from PIL import Image
except ImportError:
try:
import Image
except ImportError: except ImportError:
Image = None Image = None
@ -53,7 +50,7 @@ def get_image_size(filename):
if size[0] == -1: if size[0] == -1:
size = None size = None
if size is None and Image: # fallback to PIL if size is None and Image: # fallback to Pillow
im = Image.open(filename) im = Image.open(filename)
size = im.size size = im.size
try: try: