Skip to content

Commit

Permalink
Merge pull request #7105 from bigcat88/load-before-deepcopy
Browse files Browse the repository at this point in the history
Load before getting size in __getstate__
  • Loading branch information
radarhere authored Apr 23, 2023
2 parents 0f389c7 + dbfe2fb commit 48a6c3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Tests/test_image_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from PIL import Image

from .helper import hopper
from .helper import hopper, skip_unless_feature


@pytest.mark.parametrize("mode", ("1", "P", "L", "RGB", "I", "F"))
Expand Down Expand Up @@ -42,3 +42,10 @@ def test_copy_zero():
out = im.copy()
assert out.mode == im.mode
assert out.size == im.size


@skip_unless_feature("libtiff")
def test_deepcopy():
with Image.open("Tests/images/g4_orientation_5.tif") as im:
out = copy.deepcopy(im)
assert out.size == (590, 88)
3 changes: 2 additions & 1 deletion src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,8 @@ def __array_interface__(self):
return new

def __getstate__(self):
return [self.info, self.mode, self.size, self.getpalette(), self.tobytes()]
im_data = self.tobytes() # load image first
return [self.info, self.mode, self.size, self.getpalette(), im_data]

def __setstate__(self, state):
Image.__init__(self)
Expand Down

0 comments on commit 48a6c3f

Please sign in to comment.