Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Tests/test_imagefont.py
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,13 @@ def test_variation_set_by_axes(self):
font.set_variation_by_axes([100])
self._check_text(font, "Tests/images/variation_tiny_axes.png", 32.5)

def test_textbbox_non_freetypefont(self):
im = Image.new("RGB", (200, 200))
d = ImageDraw.Draw(im)
default_font = ImageFont.load_default()
with pytest.raises(ValueError):
d.textbbox((0, 0), "test", font=default_font)

@pytest.mark.parametrize(
"anchor, left, left_old, top",
(
Expand Down
4 changes: 3 additions & 1 deletion src/PIL/ImageDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import math
import numbers

from . import Image, ImageColor
from . import Image, ImageColor, ImageFont

"""
A simple 2D drawing interface for PIL images.
Expand Down Expand Up @@ -646,6 +646,8 @@ def textbbox(

if font is None:
font = self.getfont()
if not isinstance(font, ImageFont.FreeTypeFont):
raise ValueError("Only supported for TrueType fonts")
mode = "RGBA" if embedded_color else self.fontmode
bbox = font.getbbox(
text, mode, direction, features, language, stroke_width, anchor
Expand Down