diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index db0df047f77..47ba1756eea 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -4,6 +4,7 @@ import shutil import sys from io import BytesIO +from pathlib import Path import pytest from packaging.version import parse as parse_version @@ -76,8 +77,9 @@ def _render(font, layout_engine): return img -def test_font_with_name(layout_engine): - _render(FONT_PATH, layout_engine) +@pytest.mark.parametrize("font", (FONT_PATH, Path(FONT_PATH))) +def test_font_with_name(layout_engine, font): + _render(font, layout_engine) def test_font_with_filelike(layout_engine): diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index c2956213519..c3837545b69 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -31,6 +31,7 @@ import warnings from enum import IntEnum from io import BytesIO +from pathlib import Path from . import Image from ._util import is_directory, is_path @@ -213,6 +214,8 @@ def load_from_bytes(f): ) if is_path(font): + if isinstance(font, Path): + font = str(font) if sys.platform == "win32": font_bytes_path = font if isinstance(font, bytes) else font.encode() try: