mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-14 19:36:38 +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 import Image
|
||||||
from PIL._util import py3
|
from PIL._util import py3
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
|
||||||
class TestImage(PillowTestCase):
|
class TestImage(PillowTestCase):
|
||||||
|
@ -121,6 +123,16 @@ class TestImage(PillowTestCase):
|
||||||
im.paste(0, (0, 0, 100, 100))
|
im.paste(0, (0, 0, 100, 100))
|
||||||
self.assertFalse(im.readonly)
|
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):
|
def test_dump(self):
|
||||||
im = Image.new("L", (10, 10))
|
im = Image.new("L", (10, 10))
|
||||||
im._dump(self.tempfile("temp_L.ppm"))
|
im._dump(self.tempfile("temp_L.ppm"))
|
||||||
|
|
|
@ -1958,7 +1958,7 @@ class Image(object):
|
||||||
filename = fp.name
|
filename = fp.name
|
||||||
|
|
||||||
# may mutate self!
|
# may mutate self!
|
||||||
self.load()
|
self._ensure_mutable()
|
||||||
|
|
||||||
save_all = params.pop('save_all', False)
|
save_all = params.pop('save_all', False)
|
||||||
self.encoderinfo = params
|
self.encoderinfo = params
|
||||||
|
|
Loading…
Reference in New Issue
Block a user