Skip to content

Commit

Permalink
Copy palette to new image in transform()
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Jul 30, 2021
1 parent 6cb127c commit b5428a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Tests/test_image_transform.py
Expand Up @@ -32,6 +32,11 @@ def test_info(self):
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
Expand Down
2 changes: 2 additions & 0 deletions src/PIL/Image.py
Expand Up @@ -2479,6 +2479,8 @@ def getdata(self):
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
Expand Down

0 comments on commit b5428a7

Please sign in to comment.