Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 105d755

Browse files
authored
Merge pull request #15571 from timhoffm/pillow-cleanup
Cleanup following using Pillow as universal image reader
2 parents 90fc3dc + 775c700 commit 105d755

File tree

6 files changed

+14
-33
lines changed

6 files changed

+14
-33
lines changed

INSTALL.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ To run the test suite:
4646
* extract the :file:`lib/matplotlib/tests` or :file:`lib/mpl_toolkits/tests`
4747
directories from the source distribution;
4848
* install test dependencies: `pytest <https://pypi.org/project/pytest>`_,
49-
Pillow, MiKTeX, GhostScript, ffmpeg, avconv, ImageMagick, and `Inkscape
49+
MiKTeX, GhostScript, ffmpeg, avconv, ImageMagick, and `Inkscape
5050
<https://inkscape.org/>`_;
5151
* run ``python -mpytest``.
5252

@@ -115,6 +115,7 @@ Matplotlib requires the following dependencies:
115115
* `cycler <http://matplotlib.org/cycler/>`_ (>= 0.10.0)
116116
* `dateutil <https://pypi.org/project/python-dateutil>`_ (>= 2.1)
117117
* `kiwisolver <https://github.com/nucleic/kiwi>`_ (>= 1.0.0)
118+
* `Pillow <https://pillow.readthedocs.io/en/latest/>`_ (>= 6.2)
118119
* `pyparsing <https://pyparsing.wikispaces.com/>`_
119120

120121
Optionally, you can also install a number of packages to enable better user
@@ -149,8 +150,6 @@ etc., you can install the following:
149150
<https://libav.org/avconv.html>`_: for saving movies;
150151
* `ImageMagick <https://www.imagemagick.org/script/index.php>`_: for saving
151152
animated gifs;
152-
* `Pillow <https://pillow.readthedocs.io/en/latest/>`_ (>= 3.4): for a larger
153-
selection of image file formats: JPEG, BMP, and TIFF image files;
154153
* `LaTeX <https://miktex.org/>`_ and `GhostScript (>=9.0)
155154
<https://ghostscript.com/download/>`_ : for rendering text with LaTeX.
156155

lib/matplotlib/figure.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,9 +2143,7 @@ def savefig(self, fname, *, transparent=None, **kwargs):
21432143
21442144
pil_kwargs : dict, optional
21452145
Additional keyword arguments that are passed to `PIL.Image.save`
2146-
when saving the figure. Only applicable for formats that are saved
2147-
using Pillow, i.e. JPEG, TIFF, and (if the keyword is set to a
2148-
non-None value) PNG.
2146+
when saving the figure.
21492147
"""
21502148

21512149
kwargs.setdefault('dpi', rcParams['savefig.dpi'])

lib/matplotlib/image.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,8 +1628,9 @@ def thumbnail(infile, thumbfile, scale=0.1, interpolation='bilinear',
16281628
Parameters
16291629
----------
16301630
infile : str or file-like
1631-
The image file -- must be PNG, or Pillow-readable if you have Pillow_
1632-
installed.
1631+
The image file. Matplotlib relies on Pillow_ for image reading, and
1632+
thus supports a wide range of file formats, including PNG, JPG, TIFF
1633+
and others.
16331634
16341635
.. _Pillow: http://python-pillow.org/
16351636

lib/matplotlib/tests/test_agg.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import numpy as np
44
from numpy.testing import assert_array_almost_equal
5+
from PIL import Image, TiffTags
56
import pytest
67

8+
79
from matplotlib import (
810
collections, path, pyplot as plt, transforms as mtransforms, rcParams)
911
from matplotlib.image import imread
@@ -217,7 +219,6 @@ def test_chunksize():
217219

218220
@pytest.mark.backend('Agg')
219221
def test_jpeg_dpi():
220-
Image = pytest.importorskip("PIL.Image")
221222
# Check that dpi is set correctly in jpg files.
222223
plt.plot([0, 1, 2], [0, 1, 0])
223224
buf = io.BytesIO()
@@ -227,7 +228,6 @@ def test_jpeg_dpi():
227228

228229

229230
def test_pil_kwargs_png():
230-
Image = pytest.importorskip("PIL.Image")
231231
from PIL.PngImagePlugin import PngInfo
232232
buf = io.BytesIO()
233233
pnginfo = PngInfo()
@@ -238,11 +238,9 @@ def test_pil_kwargs_png():
238238

239239

240240
def test_pil_kwargs_tiff():
241-
Image = pytest.importorskip("PIL.Image")
242-
from PIL.TiffTags import TAGS_V2 as TAGS
243241
buf = io.BytesIO()
244242
pil_kwargs = {"description": "test image"}
245243
plt.figure().savefig(buf, format="tiff", pil_kwargs=pil_kwargs)
246244
im = Image.open(buf)
247-
tags = {TAGS[k].name: v for k, v in im.tag_v2.items()}
245+
tags = {TiffTags.TAGS_V2[k].name: v for k, v in im.tag_v2.items()}
248246
assert tags["ImageDescription"] == "test image"

lib/matplotlib/tests/test_animation.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ def isAvailable(cls):
132132
# matplotlib.testing.image_comparison
133133
@pytest.mark.parametrize('writer, output', WRITER_OUTPUT)
134134
def test_save_animation_smoketest(tmpdir, writer, output):
135-
if writer == 'pillow':
136-
pytest.importorskip("PIL")
137135
try:
138136
# for ImageMagick the rcparams must be patched to account for
139137
# 'convert' being a built in MS tool, not the imagemagick

lib/matplotlib/tests/test_image.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import numpy as np
1212
from numpy import ma
1313
from numpy.testing import assert_array_equal
14+
from PIL import Image
1415

1516
from matplotlib import (
1617
colors, image as mimage, patches, pyplot as plt, style, rcParams)
@@ -219,31 +220,24 @@ def test_imshow_zoom(fig_test, fig_ref):
219220
@check_figures_equal()
220221
def test_imshow_pil(fig_test, fig_ref):
221222
style.use("default")
222-
PIL = pytest.importorskip("PIL")
223-
# Pillow<=6.0 fails to open pathlib.Paths on Windows (pillow#3823), and
224-
# Matplotlib's builtin png opener doesn't handle them either.
225-
png_path = str(
226-
Path(__file__).parent / "baseline_images/pngsuite/basn3p04.png")
227-
tiff_path = str(
228-
Path(__file__).parent / "baseline_images/test_image/uint16.tif")
223+
png_path = Path(__file__).parent / "baseline_images/pngsuite/basn3p04.png"
224+
tiff_path = Path(__file__).parent / "baseline_images/test_image/uint16.tif"
229225
axs = fig_test.subplots(2)
230-
axs[0].imshow(PIL.Image.open(png_path))
231-
axs[1].imshow(PIL.Image.open(tiff_path))
226+
axs[0].imshow(Image.open(png_path))
227+
axs[1].imshow(Image.open(tiff_path))
232228
axs = fig_ref.subplots(2)
233229
axs[0].imshow(plt.imread(png_path))
234230
axs[1].imshow(plt.imread(tiff_path))
235231

236232

237233
def test_imread_pil_uint16():
238-
pytest.importorskip("PIL")
239234
img = plt.imread(os.path.join(os.path.dirname(__file__),
240235
'baseline_images', 'test_image', 'uint16.tif'))
241236
assert img.dtype == np.uint16
242237
assert np.sum(img) == 134184960
243238

244239

245240
def test_imread_fspath():
246-
pytest.importorskip("PIL")
247241
img = plt.imread(
248242
Path(__file__).parent / 'baseline_images/test_image/uint16.tif')
249243
assert img.dtype == np.uint16
@@ -252,8 +246,6 @@ def test_imread_fspath():
252246

253247
@pytest.mark.parametrize("fmt", ["png", "jpg", "jpeg", "tiff"])
254248
def test_imsave(fmt):
255-
if fmt in ["jpg", "jpeg", "tiff"]:
256-
pytest.importorskip("PIL")
257249
has_alpha = fmt not in ["jpg", "jpeg"]
258250

259251
# The goal here is that the user can specify an output logical DPI
@@ -318,7 +310,6 @@ def test_imsave_color_alpha():
318310

319311

320312
def test_imsave_pil_kwargs_png():
321-
Image = pytest.importorskip("PIL.Image")
322313
from PIL.PngImagePlugin import PngInfo
323314
buf = io.BytesIO()
324315
pnginfo = PngInfo()
@@ -330,7 +321,6 @@ def test_imsave_pil_kwargs_png():
330321

331322

332323
def test_imsave_pil_kwargs_tiff():
333-
Image = pytest.importorskip("PIL.Image")
334324
from PIL.TiffTags import TAGS_V2 as TAGS
335325
buf = io.BytesIO()
336326
pil_kwargs = {"description": "test image"}
@@ -668,7 +658,6 @@ def test_nonuniformimage_setnorm():
668658

669659

670660
def test_jpeg_2d():
671-
Image = pytest.importorskip('PIL.Image')
672661
# smoke test that mode-L pillow images work.
673662
imd = np.ones((10, 10), dtype='uint8')
674663
for i in range(10):
@@ -680,8 +669,6 @@ def test_jpeg_2d():
680669

681670

682671
def test_jpeg_alpha():
683-
Image = pytest.importorskip('PIL.Image')
684-
685672
plt.figure(figsize=(1, 1), dpi=300)
686673
# Create an image that is all black, with a gradient from 0-1 in
687674
# the alpha channel from left to right.

0 commit comments

Comments
 (0)