diff --git a/Tests/test_image.py b/Tests/test_image.py index c4e6f8ade..2d661a903 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -149,10 +149,11 @@ class TestImage: assert im.mode == "RGB" assert im.size == (128, 128) - temp_file = str(tmp_path / "temp.jpg") - if os.path.exists(temp_file): - os.remove(temp_file) - im.save(Path(temp_file)) + for ext in (".jpg", ".jp2"): + temp_file = str(tmp_path / ("temp." + ext)) + if os.path.exists(temp_file): + os.remove(temp_file) + im.save(Path(temp_file)) def test_fp_name(self, tmp_path): temp_file = str(tmp_path / "temp.jpg") diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 34959cddd..5d565f613 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2180,12 +2180,12 @@ class Image: filename = "" open_fp = False - if isPath(fp): - filename = fp - open_fp = True - elif isinstance(fp, Path): + if isinstance(fp, Path): filename = str(fp) open_fp = True + elif isPath(fp): + filename = fp + open_fp = True elif fp == sys.stdout: try: fp = sys.stdout.buffer