Skip to content

Converting P->RGB, modifying, and converting back to P results in incorrect palette #513

@gasman

Description

@gasman

Running this script (which converts a paletted image to RGB, resizes it with antialiasing enabled, and converts it back to paletted) on the provided in.gif results in an image with a broken palette.

From git bisect, the offending commit is 06301c9 - this suggests that it's holding on to the image's original palette, which is no longer valid after the RGB data is modified by the resize operation. (The bug is avoided if you save and reopen the image while it is in RGB mode, immediately before or after the image.resize line.)

from PIL import Image

image = Image.open('in.gif')
image = image.convert('RGB')
image = image.resize((200, 150), Image.ANTIALIAS)
image = image.convert('P', palette=Image.ADAPTIVE, colors=256)
image.save('out.png')

in.gif:
in

out.png with Pillow 2.2.2:
out-pillow 2 2 2

out.png with Pillow 2.3.0:
out-pillow 2 3 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugAny unexpected behavior, until confirmed feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions