New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support setting a default font #6480
Comments
If you're looking for an immediate solution, you could patch Pillow. Using one of our test fonts, from PIL import ImageFont
ImageFont.load_default = lambda: ImageFont.truetype("Tests/fonts/NotoSansJP-Regular.otf") In context, from PIL import Image, ImageDraw, ImageFont
ImageFont.load_default = lambda: ImageFont.truetype("Tests/fonts/NotoSansJP-Regular.otf")
im = Image.new("RGB", (400, 300))
draw = ImageDraw.Draw(im)
draw.text((10, 10), "你好")
im.show() |
Awesome! I am practicing an identical workaround. |
What do you think of this interface for setting a default font? from PIL import ImageDraw, ImageFont
ImageDraw.ImageDraw.font = ImageFont.truetype("Tests/fonts/FreeMono.ttf", 120) I've created PR #6484 with this change. |
Looks good, but why does it go under |
You can already set the default font on a per- from PIL import Image, ImageDraw, ImageFont
im = Image.new("RGB", (400, 300))
draw = ImageDraw.Draw(im)
draw.font = ImageFont.truetype("Tests/fonts/NotoSansJP-Regular.otf")
draw.text((10, 10), "你好")
im.show() This is currently undocumented, but I wouldn't expect it to be removed without a deprecation notice. Perhaps just documenting this field would be good enough for you? @radarhere's PR adds the option to set a default value globally for all
|
Yeah, the constant constraint makes sense to me. |
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 programtext()
with a font?What actually happened?
Checking the docs there's
PIL.ImageFont.load_default()
toWhat are your OS, Python and Pillow versions?
It gives:
The text was updated successfully, but these errors were encountered: