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

Skip to content

Commit bb99770

Browse files
committed
FIX: account for constant deprecations in Pillow 9.1
https://pillow.readthedocs.io/en/stable/deprecations.html#constants https://pillow.readthedocs.io/en/stable/releasenotes/9.1.0.html#constants Image.None -> Image.Dither.None Image.ADAPTIVE -> Image.Palette.ADAPTIVE
1 parent 20e38f4 commit bb99770

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/matplotlib/backends/backend_pdf.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,8 +1700,19 @@ def _writeImg(self, data, id, smask=None):
17001700
# Convert to indexed color if there are 256 colors or fewer
17011701
# This can significantly reduce the file size
17021702
num_colors = len(img_colors)
1703-
img = img.convert(mode='P', dither=Image.NONE,
1704-
palette=Image.ADAPTIVE, colors=num_colors)
1703+
# These constants were converted to IntEnums and deprecated in
1704+
# Pillow 9.2
1705+
dither = (
1706+
Image.Dither.NONE if hasattr(Image, 'Dither')
1707+
else Image.NONE
1708+
)
1709+
pmode = (
1710+
Image.Palette.ADAPTIVE if hasattr(Image, 'Palette')
1711+
else Image.ADAPTIVE
1712+
)
1713+
img = img.convert(
1714+
mode='P', dither=dither, palette=pmode, colors=num_colors
1715+
)
17051716
png_data, bit_depth, palette = self._writePng(img)
17061717
if bit_depth is None or palette is None:
17071718
raise RuntimeError("invalid PNG header")

0 commit comments

Comments
 (0)