nir / jupylet

Python game programming in Jupyter notebooks.
https://jupylet.readthedocs.io
BSD 2-Clause "Simplified" License
227 stars 21 forks source link

AttributeError: 'FreeTypeFont' object has no attribute 'getsize' with Pillow 10 #41

Open misolietavec opened 10 months ago

misolietavec commented 10 months ago

right in example 02-hello-jupylet. This issue I found also in tensorflow, see this URL, where it was successfully resolved. I think, ipyleaflet can go this way, too (using old, deprecated getsize if it is available, or getbbox if it is not.

nir commented 10 months ago

what version of python, and jupylet ?

misolietavec commented 10 months ago

python 3.11 in conda environment, latest jupylet from github/master, this is only the question of Pillow version (here I have version 10.0.1). The solution is simply to modify the function draw_chr in file label.py as follows:

@functools.lru_cache(maxsize=2048)
def draw_chr(c, path, size):

    font = load_font(path, size)
    if hasattr(font, 'getsize'):
        w, h = font.getsize(c)
    else:
        w, h = font.getbbox(c)[2:4]

    im = PIL.Image.new('L', (w, h))
    di = PIL.ImageDraw.Draw(im)
    di.text((0, 0), c, fill='white', font=font)

    return np.array(im)
nir commented 10 months ago

coming up - I pushed your fix to github along with other overdue changes (before a new release) - please pull and check it is fixed on your system - gave you the credit here https://github.com/nir/jupylet#whats-new-in-version-091.

thanks!

nir commented 10 months ago

oh, but please install it into a clean virtual environment

misolietavec commented 10 months ago

All OK.

nir commented 10 months ago

fix released with jupylet 0.9.1

thanks!

misolietavec commented 10 months ago

I think, you can close this issue now.