Ensure image is mutable before saving

This commit is contained in:
Andrew Murray 2019-03-17 23:37:40 +11:00
parent d1f865e02a
commit 0b62337b6f
2 changed files with 13 additions and 1 deletions

View File

@ -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"))

View File

@ -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