Skip to content

Cannot pickle ImageFont objects #5825

@albertlis

Description

@albertlis

What did you do?

I'm trying to pickle TrueType ImageFont font:

from PIL import ImageFont
import pickle

font = ImageFont.truetype('2Dumb.ttf', size=30)
pickled = pickle.dumps(font, protocol=pickle.HIGHEST_PROTOCOL)

What did you expect to happen?

Font object should be correctly pickled.

What actually happened?

The following error was thrown:

Traceback (most recent call last):
  File "C:\Users\alis\.virtualenvs\ocr-BMJCq2bR\lib\site-packages\IPython\core\interactiveshell.py", line 3444, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-5-f334d76ecd99>", line 1, in <module>
    pickled = pickle.dumps(font, protocol=pickle.HIGHEST_PROTOCOL)
TypeError: cannot pickle 'Font' object

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: 3.9.6
  • Pillow: 8.4.0
  • Font: 2Dumb.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions