Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy palette to new image in transform() #5647

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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