-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Description
What did you do?
I have some code I use to render text as images. When trying to render an empty string, it fails on Image.frombytes
What did you expect to happen?
I expected Image.frombytes with size (0, 0) and bytes [] (as a numpy array of uint8) to successfully yield an empty image.
What actually happened?
An exception is thrown:
Traceback (most recent call last):
File "/home/devin/Desktop/pyblox/netsblox/turtle.py", line 89, in wrapped
fn(*args, **kwargs)
File "/home/devin/Desktop/pyblox/netsblox/turtle.py", line 119, in wrapped
return f(*args, **kwargs)
File "<stdin>", line 34, in my_onstart
File "/home/devin/Desktop/pyblox/netsblox/turtle.py", line 1250, in say
imgs = [_render_text(x, size = 8, color = (0, 0, 0)) for x in lines]
File "/home/devin/Desktop/pyblox/netsblox/turtle.py", line 1250, in <listcomp>
imgs = [_render_text(x, size = 8, color = (0, 0, 0)) for x in lines]
File "/home/devin/Desktop/pyblox/netsblox/turtle.py", line 80, in _render_text
text_mask = Image.frombytes('L', text_mask.size, _np.array(text_mask).astype(_np.uint8)) # convert ImagingCore to Image
File "/home/devin/.local/lib/python3.8/site-packages/PIL/Image.py", line 2976, in frombytes
im.frombytes(data, decoder_name, args)
File "/home/devin/.local/lib/python3.8/site-packages/PIL/Image.py", line 804, in frombytes
d.setimage(self.im)
ValueError: tile cannot extend outside imageWhat are your OS, Python and Pillow versions?
- OS: Linux Mint 20
- Python: 3.8.10
- Pillow: 10.1.0
font = ImageFont.truetype('example-font.otf')
text = ''
color = (0, 0, 0)
text_mask = font.getmask(text, mode = 'L')
text_mask = Image.frombytes('L', text_mask.size, _np.array(text_mask).astype(_np.uint8)) # fails here with exceptionMetadata
Metadata
Assignees
Labels
No labels