diff --git a/Tests/test_image_transform.py b/Tests/test_image_transform.py index 845900267..ea208362b 100644 --- a/Tests/test_image_transform.py +++ b/Tests/test_image_transform.py @@ -32,6 +32,11 @@ class TestImageTransform: new_im = im.transform((100, 100), transform) assert new_im.info["comment"] == comment + def test_palette(self): + with Image.open("Tests/images/hopper.gif") as im: + transformed = im.transform(im.size, Image.AFFINE, [1, 0, 0, 0, 1, 0]) + assert im.palette.palette == transformed.palette.palette + def test_extent(self): im = hopper("RGB") (w, h) = im.size diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 5d565f613..e31e0371e 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -2479,6 +2479,8 @@ class Image: raise ValueError("missing method data") im = new(self.mode, size, fillcolor) + if self.mode == "P" and self.palette: + im.palette = self.palette.copy() im.info = self.info.copy() if method == MESH: # list of quads