DEV Community

Discussion on: How Haptik generates images on the fly with Python

Collapse
 
waracci profile image
Morris Warachi

Traceback (most recent call last):
File "image.py", line 28, in
draw.text((x, y), message, fill=color, font=font)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageDraw.py", line 213, in text
ink, fill = self._getink(fill)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImageDraw.py", line 111, in _getink
ink = self.palette.getcolor(ink)
File "/usr/local/lib/python2.7/dist-packages/PIL/ImagePalette.py", line 107, in getcolor
self.palette[index+256] = color[1]
IndexError: bytearray index out of range

Thread Thread
 
vinayjn profile image
Vinay Jain

Thanks Morris,

Looks like you don't have fonts installed on your system. I missed this step in the post. The way Pillow works is that it builds on top of the fonts installed in the system. To fix the errors you are getting please install the fonts by following:

Ubuntu: How to install fonts on Ubuntu

For macOS and Windows just open the fonts files which you have downloaded.

Thread Thread
 
waracci profile image
Morris Warachi

Thanks for the response Vinay Jain. I will try installing the Roboto font and see if it works. Again, thanks for the help.