Copy palette in expand() for PA

This commit is contained in:
Andrew Murray 2022-09-19 21:39:38 +10:00
parent 279ddf4ce6
commit 3c42b270b9
2 changed files with 4 additions and 3 deletions

View File

@ -130,8 +130,9 @@ def test_pad():
) )
def test_palette(): @pytest.mark.parametrize("mode", ("P", "PA"))
im = hopper("P") def test_palette(mode):
im = hopper(mode)
# Expand # Expand
expanded_im = ImageOps.expand(im) expanded_im = ImageOps.expand(im)

View File

@ -398,7 +398,7 @@ def expand(image, border=0, fill=0):
width = left + image.size[0] + right width = left + image.size[0] + right
height = top + image.size[1] + bottom height = top + image.size[1] + bottom
color = _color(fill, image.mode) color = _color(fill, image.mode)
if image.mode == "P" and image.palette: if image.palette:
palette = ImagePalette.ImagePalette(palette=image.getpalette()) palette = ImagePalette.ImagePalette(palette=image.getpalette())
if isinstance(color, tuple): if isinstance(color, tuple):
color = palette.getcolor(color) color = palette.getcolor(color)