mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
Ensure image is mutable before saving
This commit is contained in:
parent
d1f865e02a
commit
0b62337b6f
|
@ -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"))
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user