Skip to content
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

Default font with provided font size? #2695

Closed
yuanxu-li opened this issue Aug 23, 2017 · 4 comments
Closed

Default font with provided font size? #2695

yuanxu-li opened this issue Aug 23, 2017 · 4 comments

Comments

@yuanxu-li
Copy link

There are at least two ways to get a font, either loading from default or reading from a file, such as:

from PIL import ImageFont
default_font = ImageFont.load_default()
provided_font = ImageFont.truetype("sans-serif.ttf", 16)

I am wondering if there is any way that I can use the default font with a given font size, such as:

from PIL import ImageFont
default_font = ImageFont.load_default(size=16)

to save myself the trouble of providing a font file while being able to change the font size.

@wiredfool
Copy link
Member

No, the default font is a bitmapped font with no alternate sizes.

@paalbra
Copy link

paalbra commented Dec 21, 2020

There is still no workaround or anything for this?

It would be nice if Pillow provided a default font that "just works" and you were able to set a font size for it.

@kylekyle
Copy link

kylekyle commented Feb 21, 2022

Right now PIllow doesn't ship with a font that can be resized. You probably already have a library that ships with one, so you could just load that. For example:

import os
import cv2

font_path = os.path.join(cv2.__path__[0],'qt','fonts','DejaVuSans.ttf')
font = ImageFont.truetype(font_path, size=128)

@radarhere
Copy link
Member

For those seeking a default font that can change sizes, #6622 has been created as a request for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants