Skip to content

Support setting a default font #6480

@guoquan

Description

@guoquan

What did you do?

Was printing CJK characters to an image but got an AttributeError. No doubt the default font wasn't supporting such characters.

What did you expect to happen?

Understand I can use Unicode-friendly fonts everytime I do text(). However, can I somehow change the default font so that I won't need to change everywhere in my program text() with a font?

What actually happened?

Checking the docs there's PIL.ImageFont.load_default() to

Load a “better than nothing” default font.
Well, it is very clear.
But can I provide some "better than nothing" default for my own use?

What are your OS, Python and Pillow versions?

  • OS: Ubuntu
  • Python: 3.8.13
  • Pillow: 9.2.0
from PIL import Image, ImageDraw

im = Image.new("RGB", (400, 300))
draw = ImageDraw.Draw(im)
draw.text((10, 10), "你好")

im.show()

It gives:

AttributeError: 'ImageFont' object has no attribute 'getmask2'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions