jupylet icon indicating copy to clipboard operation
jupylet copied to clipboard

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

Open misolietavec opened this issue 1 year ago • 7 comments

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.

misolietavec avatar Oct 28 '23 08:10 misolietavec

what version of python, and jupylet ?

nir avatar Oct 28 '23 12:10 nir

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)

misolietavec avatar Oct 28 '23 16:10 misolietavec

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 avatar Oct 28 '23 20:10 nir

oh, but please install it into a clean virtual environment

nir avatar Oct 28 '23 21:10 nir

All OK.

misolietavec avatar Oct 29 '23 08:10 misolietavec

fix released with jupylet 0.9.1

thanks!

nir avatar Oct 29 '23 19:10 nir

I think, you can close this issue now.

misolietavec avatar Nov 05 '23 11:11 misolietavec