return copy of the image if size matches

This commit is contained in:
homm 2016-11-24 03:30:36 +03:00
parent 9947794ccd
commit d4784bffb2
2 changed files with 10 additions and 1 deletions

View File

@ -1544,7 +1544,7 @@ class Image(object):
size = tuple(size)
if self.size == size:
return self._new(self.im)
return self.copy()
if self.mode in ("1", "P"):
resample = NEAREST

View File

@ -24,6 +24,15 @@ class TestImagingResampleVulnerability(PillowTestCase):
with self.assertRaises(ValueError):
im.resize((100, -100))
def test_modify_after_resizing(self):
im = hopper('RGB')
# get copy with same size
copy = im.resize(im.size)
# some in-place operation
copy.paste('black', (0, 0, im.width // 2, im.height // 2))
# image should be different
self.assertNotEqual(im.tobytes(), copy.tobytes())
class TestImagingCoreResampleAccuracy(PillowTestCase):
def make_case(self, mode, size, color):