Skip to content

Commit

Permalink
Load image before deepcopy(__getstate__)
Browse files Browse the repository at this point in the history
Signed-off-by: bigcat88 <bigcat88@icloud.com>
  • Loading branch information
bigcat88 committed Apr 21, 2023
1 parent a405e84 commit b10379b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 9 additions & 0 deletions Tests/test_numpy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import warnings
from copy import deepcopy

import pytest

Expand Down Expand Up @@ -226,6 +227,14 @@ def test_load_first():
assert a.shape == (88, 590)


@skip_unless_feature("libtiff")
def test_load_first_deepcopy():
with Image.open("Tests/images/g4_orientation_5.tif") as im:
im_deepcopy = deepcopy(im)
a = numpy.array(im_deepcopy)
assert a.shape == (88, 590)


def test_bool():
# https://github.com/python-pillow/Pillow/issues/2044
a = numpy.zeros((10, 2), dtype=bool)
Expand Down
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 b10379b

Please sign in to comment.