Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
misolietavec opened this issue Oct 28, 2023 · 7 comments

Comments

@misolietavec
Copy link

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
Copy link
Owner

nir commented Oct 28, 2023

what version of python, and jupylet ?

@misolietavec
Copy link
Author

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
Copy link
Owner

nir commented Oct 28, 2023

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
Copy link
Owner

nir commented Oct 28, 2023

oh, but please install it into a clean virtual environment

@misolietavec
Copy link
Author

All OK.

@nir
Copy link
Owner

nir commented Oct 29, 2023

fix released with jupylet 0.9.1

thanks!

@misolietavec
Copy link
Author

I think, you can close this issue now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants