pklaus / brother_ql_web

A Python-based web service to print labels on Brother QL label printers. Based on brother_ql: https://github.com/pklaus/brother_ql
GNU General Public License v3.0
254 stars 124 forks source link

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

Open netmilk opened 8 months ago

netmilk commented 8 months ago

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 commented 8 months ago

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.