Skip to content

Commit

Permalink
Fix PIL import in savefig.py
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiodsf committed Feb 19, 2024
1 parent 3f62435 commit 0f33577
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sourcespec/savefig.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import io
import logging
import warnings
import PIL
from PIL import Image
# Reduce logging level for PIL to avoid DEBUG messages
pil_logger = logging.getLogger('PIL')
pil_logger.setLevel(logging.WARNING)
Expand All @@ -30,9 +30,10 @@ def savefig(fig, figfile, fmt, quantize_colors=True, **kwargs):
buf = io.BytesIO()
fig.savefig(buf, format='png', **kwargs)
buf.seek(0)
img = PIL.Image.open(buf)
img = Image.open(buf)
if quantize_colors:
img = img.convert('P', palette=PIL.Image.ADAPTIVE, colors=256)
# pylint: disable=maybe-no-member
img = img.convert('P', palette=Image.ADAPTIVE, colors=256)
else:
# just remove the alpha channel
img = img.convert('RGB')
Expand Down

0 comments on commit 0f33577

Please sign in to comment.