Replit will not recognise ttf files as fonts for use with Pillow

When I add a true type font to my repl through ImageFont in PIL, it doesn’t recognise it as a font. The program works perfectly on my computer, but the second I upload it to Repl, it stops working. I have tried loading the files in from the local directory and loading them in from the github source repo, both of which give the same error, which leads me to believe it is a problem with the decoding of the .ttf file itself. The error message is as follows:

  File "main.py", line 127, in create_image
    font = ImageFont.truetype(io.BytesIO(reg.content), 115)
  File "/home/runner/balls/venv/lib/python3.8/site-packages/PIL/ImageFont.py", line 959, in truetype
    return freetype(font)
  File "/home/runner/balls/venv/lib/python3.8/site-packages/PIL/ImageFont.py", line 956, in freetype
    return FreeTypeFont(font, size, index, encoding, layout_engine)
  File "/home/runner/balls/venv/lib/python3.8/site-packages/PIL/ImageFont.py", line 251, in __init__
    load_from_bytes(font)
  File "/home/runner/balls/venv/lib/python3.8/site-packages/PIL/ImageFont.py", line 232, in load_from_bytes
    self.font = core.getfont(
OSError: unknown file format

Welcome To Forums @FatsoIdiot

I don’t know what exactly your program code is about but the error you mentions above is files path error you ran the program on your pc and that path is saved in program may be you need to see the path when uploaded to replit and correct it.

Also see if you need to import the package lib to program.

For more help on code error if possible share repl link so we could look in that.

1 Like