diff --git a/Tests/test_image.py b/Tests/test_image.py index 83dac7080..d1a385a35 100644 --- a/Tests/test_image.py +++ b/Tests/test_image.py @@ -94,6 +94,18 @@ class TestImage: # 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): diff --git a/src/PIL/Image.py b/src/PIL/Image.py index a79666d7a..89034da3a 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -826,6 +826,10 @@ class Image: :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()