diff --git a/Tests/test_image.py b/Tests/test_image.py index b11ad1a3b..5bfcde368 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -3,6 +3,8 @@ from .helper import unittest, PillowTestCase, hopper from PIL import Image from PIL._util import py3 import os +import sys +import shutil class TestImage(PillowTestCase): @@ -121,6 +123,16 @@ class TestImage(PillowTestCase): im.paste(0, (0, 0, 100, 100)) self.assertFalse(im.readonly) + @unittest.skipIf(sys.platform.startswith('win32'), + "Test requires opening tempfile twice") + def test_readonly_save(self): + temp_file = self.tempfile("temp.bmp") + shutil.copy("Tests/images/rgb32bf-rgba.bmp", temp_file) + + im = Image.open(temp_file) + self.assertTrue(im.readonly) + im.save(temp_file) + def test_dump(self): im = Image.new("L", (10, 10)) im._dump(self.tempfile("temp_L.ppm")) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 99756264b..ed3719100 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1958,7 +1958,7 @@ class Image(object): filename = fp.name # may mutate self! - self.load() + self._ensure_mutable() save_all = params.pop('save_all', False) self.encoderinfo = params