From b959a25f098c8aace45224564ef993b7b009df2f Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 27 Feb 2016 13:10:50 +1100 Subject: [PATCH] Fixed bug when saving to a non-existent path using pathlib --- PIL/Image.py | 2 +- Tests/test_image.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/PIL/Image.py b/PIL/Image.py index 6d0fe4fc39f..3f597ba50d3 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -1636,7 +1636,7 @@ def save(self, fp, format=None, **params): elif sys.version_info >= (3, 4): from pathlib import Path if isinstance(fp, Path): - filename = str(fp.resolve()) + filename = str(fp) open_fp = True elif hasattr(fp, "name") and isPath(fp.name): # only set the name for metadata purposes diff --git a/Tests/test_image.py b/Tests/test_image.py index 59ffcd11400..a9c168fa7b1 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -1,6 +1,7 @@ from helper import unittest, PillowTestCase, hopper from PIL import Image +import os import sys @@ -57,6 +58,11 @@ def test_pathlib(self): self.assertEqual(im.mode, "RGB") self.assertEqual(im.size, (128, 128)) + temp_file = self.tempfile("temp.jpg") + if os.path.exists(temp_file): + os.remove(temp_file) + im.save(Path(temp_file)) + def test_tempfile(self): # see #1460, pathlib support breaks tempfile.TemporaryFile on py27 # Will error out on save on 3.0.0