Copy palette to new images in expand

This commit is contained in:
Andrew Murray 2021-06-19 21:24:58 +10:00
parent 384a4bf01e
commit 6639b2af7f
2 changed files with 8 additions and 0 deletions

View File

@ -156,6 +156,12 @@ def test_scale():
assert newimg.size == (25, 25)
def test_expand_palette():
im = Image.open("Tests/images/hopper.gif")
im_expanded = ImageOps.expand(im)
assert_image_equal(im_expanded.convert("RGB"), im.convert("RGB"))
def test_colorize_2color():
# Test the colorizing function with 2-color functionality

View File

@ -393,6 +393,8 @@ def expand(image, border=0, fill=0):
width = left + image.size[0] + right
height = top + image.size[1] + bottom
out = Image.new(image.mode, (width, height), _color(fill, image.mode))
if image.mode == "P" and image.palette:
out.putpalette(image.palette)
out.paste(image, (left, top))
return out