Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ def save(self, fp, format=None, **params):
if isinstance(fp, Path):
filename = str(fp)
open_fp = True
elif hasattr(fp, "name") and isPath(fp.name):
if not filename and hasattr(fp, "name") and isPath(fp.name):
# only set the name for metadata purposes
filename = fp.name

Expand Down
12 changes: 12 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ def test_pathlib(self):
os.remove(temp_file)
im.save(Path(temp_file))

def test_fp_name(self):
temp_file = self.tempfile("temp.jpg")

class FP(object):
def write(a, b):
pass
fp = FP()
fp.name = temp_file

im = hopper()
im.save(fp)

def test_tempfile(self):
# see #1460, pathlib support breaks tempfile.TemporaryFile on py27
# Will error out on save on 3.0.0
Expand Down