Skip to content

Commit ffa1a27

Browse files
committed
Update Pillow code in example
New version of Pillow has type hints and breaking changes.
1 parent f166816 commit ffa1a27

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
"GAMECONTROLLER",
164164
"gamepad",
165165
"genindex",
166+
"getbbox",
166167
"GFORCE",
167168
"GLES",
168169
"globaltoc",

examples/sdl-hello-world.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pathlib import Path
44

55
import numpy as np
6-
from PIL import Image, ImageDraw, ImageFont # type: ignore # pip install Pillow
6+
from PIL import Image, ImageDraw, ImageFont # pip install Pillow
77

88
import tcod.event
99
import tcod.sdl.render
@@ -15,8 +15,9 @@
1515

1616
def render_text(renderer: tcod.sdl.render.Renderer, text: str) -> tcod.sdl.render.Texture:
1717
"""Render text, upload it to VRAM, then return it as an SDL Texture."""
18-
# Use Pillow normally to render the font. This code is standard.
19-
width, height = font.getsize(text)
18+
# Use Pillow to render the font.
19+
_left, _top, right, bottom = font.getbbox(text)
20+
width, height = right, bottom
2021
image = Image.new("RGBA", (width, height))
2122
draw = ImageDraw.Draw(image)
2223
draw.text((0, 0), text, font=font)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ requests>=2.28.1
66
setuptools==65.5.1
77
types-cffi
88
types-requests
9+
types-Pillow
910
types-setuptools
1011
types-tabulate
1112
typing_extensions

0 commit comments

Comments
 (0)