Skip to content

Copy image when saving in GifImagePlugin - #1231

Merged
wiredfool merged 2 commits into
python-pillow:masterfrom
radarhere:image_palette
Jun 16, 2015
Merged

wiredfool merged 2 commits into
python-pillow:masterfrom
radarhere:image_palette

Conversation

@radarhere

Copy link
Copy Markdown
Member

#718 describes how saving an image in the GIF format can modify the palette of the original.

GifImagePlugin's getheader method has the comment 'create the new palette if not every color is used'. So that's why the image passed into getheader is modified.

The solution would seem to be to copy the image before passing it in.

However, this fails a few tests, because the image instance that was being checked against is no longer modified in sync with the saved file. Essentially, these tests should have been failing. I've changed the checks to similar rather than equal.

I also modified the tests affected to use copy() to try and avoid this way of sneaking past the tests in the future.

@radarhere

Copy link
Copy Markdown
Member Author

I also found that when an Image is copied, the ImagePalette remains the same instance. Rather than sharing a resource between two images, I've changed it to copy ImagePalette as well.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.01%) to 75.07% when pulling fe725bd on radarhere:image_palette into a579a90 on python-pillow:master.

1 similar comment
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.01%) to 75.07% when pulling fe725bd on radarhere:image_palette into a579a90 on python-pillow:master.

wiredfool added a commit that referenced this pull request Jun 16, 2015
Copy image when saving in GifImagePlugin
@wiredfool
wiredfool merged commit 3063190 into python-pillow:master Jun 16, 2015
@radarhere
radarhere deleted the image_palette branch June 16, 2015 22:40
@radarhere radarhere added the GIF label Mar 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants