Skip to content

Commit

Permalink
If Image is created directly, add missing core image when loading
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Oct 11, 2023
1 parent 4ecf1df commit a129937
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ def test_sanity(self):
# with pytest.raises(MemoryError):
# Image.new("L", (1000000, 1000000))

def test_direct(self):
# Test that a directly instantiated Image()
# is given a core image during load()
im = Image.Image()
assert im.im is None

im.load()
assert im.im is not None

# Test equality
assert Image.Image() == Image.Image()

def test_repr_pretty(self):
class Pretty:
def text(self, text):
Expand Down
4 changes: 4 additions & 0 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,10 @@ def load(self):
:returns: An image access object.
:rtype: :ref:`PixelAccess` or :py:class:`PIL.PyAccess`
"""
if self._mode == "":
# This image was instantiated directly
self._mode = "1"
self.im = core.new(self.mode, self.size)
if self.im is not None and self.palette and self.palette.dirty:
# realize palette
mode, arr = self.palette.getdata()
Expand Down

0 comments on commit a129937

Please sign in to comment.