Added TrueType default font to allow for different sizes by radarhere · Pull Request #7354 · python-pillow/Pillow
Resolves #6622
At the moment, Pillow's builtin font, ImageFont.load_default(), has a static size.
This PR checks if FreeType support is available, and if so, uses Aileron Regular instead, a CC0 font from https://dotcolon.net/font/aileron
Because it is CC0, we are free to change it, so I removed various characters using FontForge to reduce the file size, and converted it to TTF using https://convertio.co. This increases the size of ImageFont.py from 42kb in main to 60kb in this PR.
You might ask why I didn't convert it to WOFF or WOFF2. WOFF2 requires at least FreeType 2.10.2 which not all of our Docker jobs have, and WOFF doesn't load on some of our Docker jobs.
With a TrueType font, the size is able to be changed. In terms of our API, the following arguments are added.
ImageFont.load_default(size=24) draw.text((0, 0), "test", font_size=24) draw.textlength((0, 0), "test", font_size=24) draw.textbbox((0, 0), "test", font_size=24) draw.multiline_text((0, 0), "test", font_size=24) draw.multiline_textbbox((0, 0), "test", font_size=24)
This PR designates all of the new ImageDraw arguments as keyword arguments.
