Skip to content

Commit

Permalink
Handle pathlib.Path in FreeTypeFont
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Nov 27, 2023
1 parent f9c7bd8 commit ae7958f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Tests/test_imagefont.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions src/PIL/ImageFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit ae7958f

Please sign in to comment.