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

Workaround for AttributeError: 'FreeTypeFont' object has no attribute 'getsize' #48

Open
netmilk opened this issue Jan 14, 2024 · 1 comment

Comments

@netmilk
Copy link

netmilk commented Jan 14, 2024

The current version doesn't work. I'm no python expert at all, but downgrading Pillow worked for me as a workaround:

pip3 install Pillow==9.5.0

This is the error backtrace:

127.0.0.1 - - [14/Jan/2024 12:45:50] "POST /api/preview/text?return_format=base64 HTTP/1.1" 500 778
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/bottle.py", line 876, in _handle
    return route.call(**args)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/bottle.py", line 1759, in wrapper
    rv = callback(*a, **ka)
         ^^^^^^^^^^^^^^^^^^
  File "/Users/netmilk/projects/brother_ql_web/./brother_ql_web.py", line 192, in print_text
    im = create_label_im(**context)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/netmilk/projects/brother_ql_web/./brother_ql_web.py", line 119, in create_label_im
    linesize = im_font.getsize(text)
               ^^^^^^^^^^^^^^^
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
127.0.0.1 - - [14/Jan/2024 12:45:51] "POST /api/print/text HTTP/1.1" 500 755
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/bottle.py", line 876, in _handle
    return route.call(**args)
           ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/bottle.py", line 1759, in wrapper
    rv = callback(*a, **ka)
         ^^^^^^^^^^^^^^^^^^
  File "/Users/netmilk/projects/brother_ql_web/./brother_ql_web.py", line 152, in get_preview_image
    im = create_label_im(**context)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/netmilk/projects/brother_ql_web/./brother_ql_web.py", line 119, in create_label_im
    linesize = im_font.getsize(text)
               ^^^^^^^^^^^^^^^
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
@FriedrichFroebel
Copy link

In the easiest case, just remove the corresponding line. AFAIK the corresponding linesize variable is unused anyway. You are left with the error from #46 afterwards, which breaks compatibility with Pillow >= 10 as well.

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