brother_ql_web icon indicating copy to clipboard operation
brother_ql_web copied to clipboard

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

Open netmilk opened this issue 1 year ago • 1 comments

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'

netmilk avatar Jan 14 '24 13:01 netmilk

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.

FriedrichFroebel avatar Jan 14 '24 13:01 FriedrichFroebel