diff --git a/Tests/test_image_paste.py b/Tests/test_image_paste.py index 2cd44feaab0..e8f65ad8f6b 100644 --- a/Tests/test_image_paste.py +++ b/Tests/test_image_paste.py @@ -137,6 +137,17 @@ def test_image_solid(self, mode: str) -> None: im = im.crop((12, 23, im2.width + 12, im2.height + 23)) assert_image_equal(im, im2) + def test_image_la_into_rgb(self) -> None: + # LA images are stored with two padding bytes per pixel. + # point() sets them to zero, + # so the image must be internally converted before pasting onto RGB + im = Image.new("RGB", (1, 1)) + + source = Image.new("LA", (1, 1), (128, 255)).point(lambda v: v) + im.paste(source) + + assert im.getpixel((0, 0)) == (128, 128, 128) + @pytest.mark.parametrize("y", [10, -10]) @pytest.mark.parametrize("mode", ["L", "RGB"]) @pytest.mark.parametrize("mask_mode", ["", "1", "L", "LA", "RGBa"]) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 1b34480217c..be8e692f828 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1957,7 +1957,7 @@ def paste( source = ImageColor.getcolor(im, self.mode) elif isinstance(im, Image): if self.mode != im.mode and ( - self.mode != "RGB" or im.mode not in {"LA", "RGBA", "RGBa"} + self.mode != "RGB" or im.mode not in {"RGBA", "RGBa"} ): # should use an adapter for this! im = im.convert(self.mode)