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
261 stars 127 forks source link

no empty lines #5

Closed mueschel closed 7 years ago

mueschel commented 7 years ago

Labels can not contain empty lines. If there is a completely empty line on the label, the server returns a 500 error. If the empty line contains a space character (or any other character), the label is generated correctly.

Fails:

X

Y

Works:

X

Y
pklaus commented 7 years ago

Thanks for the bug report. I can confirm the behaviour.

With enabling --loglevel DEBUG when starting up the web server, I was able to get the traceback of the error:

Traceback (most recent call last):
  File "/python-3.5_local/lib/python3.5/site-packages/bottle.py", line 862, in _handle
    return route.call(**args)
  File "/python-3.5_local/lib/python3.5/site-packages/bottle.py", line 1740, in wrapper
    rv = callback(*a, **ka)
  File "./brother_ql_web.py", line 168, in get_preview_image
    im = create_label_im(**context)
  File "./brother_ql_web.py", line 136, in create_label_im
    textsize = draw.multiline_textsize(text, font=im_font)
  File "/python-3.5_local/lib/python3.5/site-packages/PIL/ImageDraw.py", line 269, in multiline_textsize
    direction, features)
  File "/python-3.5_local/lib/python3.5/site-packages/PIL/ImageDraw.py", line 260, in textsize
    return font.getsize(text, direction, features)
  File "/python-3.5_local/lib/python3.5/site-packages/PIL/ImageFont.py", line 156, in getsize
    size, offset = self.font.getsize(text, direction, features)
SystemError: <built-in method getsize of Font object at 0x7f0aac2e93c8> returned NULL without setting an error
127.0.0.1 - - [11/Sep/2017 11:52:04] "POST /api/preview/text?return_format=base64 HTTP/1.1" 500 2216

So the problem seems to come from PIL.ImageDraw.Draw.multiline_textsize() (see http://pillow.readthedocs.io/en/4.2.x/reference/ImageDraw.html). I think I should report the bug upstream to the Pillow project.

In the meantime, I fixed the problem with the workaround in commit 96cbe91 . It simply replaces empty lines with a line containing only a space.