Fixed opening mmap image through Path on Windows

This commit is contained in:
Andrew Murray 2019-05-04 15:00:49 +10:00
parent c15dc4d7ca
commit 691df96734
2 changed files with 7 additions and 3 deletions

View File

@ -76,6 +76,10 @@ class TestImage(PillowTestCase):
@unittest.skipUnless(Image.HAS_PATHLIB, "requires pathlib/pathlib2") @unittest.skipUnless(Image.HAS_PATHLIB, "requires pathlib/pathlib2")
def test_pathlib(self): def test_pathlib(self):
from PIL.Image import Path from PIL.Image import Path
im = Image.open(Path("Tests/images/multipage-mmap.tiff"))
self.assertEqual(im.mode, "P")
self.assertEqual(im.size, (10, 10))
im = Image.open(Path("Tests/images/hopper.jpg")) im = Image.open(Path("Tests/images/hopper.jpg"))
self.assertEqual(im.mode, "RGB") self.assertEqual(im.mode, "RGB")
self.assertEqual(im.size, (128, 128)) self.assertEqual(im.size, (128, 128))

View File

@ -2643,10 +2643,10 @@ def open(fp, mode="r"):
exclusive_fp = False exclusive_fp = False
filename = "" filename = ""
if isPath(fp): if HAS_PATHLIB and isinstance(fp, Path):
filename = fp
elif HAS_PATHLIB and isinstance(fp, Path):
filename = str(fp.resolve()) filename = str(fp.resolve())
elif isPath(fp):
filename = fp
if filename: if filename:
fp = builtins.open(filename, "rb") fp = builtins.open(filename, "rb")