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

Colors don't match images used when saving GIF #5484

Closed
julienguegan opened this issue May 10, 2021 · 5 comments
Closed

Colors don't match images used when saving GIF #5484

julienguegan opened this issue May 10, 2021 · 5 comments
Labels

Comments

@julienguegan
Copy link

julienguegan commented May 10, 2021

Hello all,

I have a weird behaviour when trying to save a .gif

Save a gif

I want to generate a gif from a sequence of image. I first create images with differents colors and transparence. Then, I save them. To generate a .gif, I read this images with Image.open() and then append them in a list.

Behaviour wanted

I want that the gif generated is exactly composed of the images I have generated/saved

What actually happened

The gif generated look a bit like that the images used but colors are not the same, I can see a frame where a part is completely black where it should be white/gray.

image in gif : image image used : image

I feel that it could be because of the transparency channel but I need to have transparency when I generate my images and also in my final .gif file ...

Configuration

  • OS: Windows 10
  • Python: 3.8.3
  • Pillow: 8.1.2

Minimal Example

import numpy as np
import matplotlib.pyplot as plt
from PIL import Image
# generate images
alphas = np.linspace(0, 1, 10)
img = np.ones((200,200,4))
for i, a in enumerate(alphas):
    img[75:125,75:125,:] = a
    plt.imsave(str(i)+'.png', img)
# save as gif
images_gif = []
for i, a in enumerate(alphas):
    im = Image.open(str(i)+'.png')
    images_gif.append(im)
    plt.imshow(np.array(im))
    plt.show()
images_gif[0].save('file.gif', save_all=True, append_images=images_gif[1:], loop=0, duration=250)
@radarhere radarhere added the GIF label May 10, 2021
@radarhere radarhere changed the title Can't generate .gif correctly. Colors don't match to images used Colors don't match images used when saving GIF May 10, 2021
@julienguegan
Copy link
Author

Just saw that it seems to be related to some previous opened issues : (#4644 and #4640). The issue does not seem to be resolved but it might exist some workaround proposed in the previous opened issues ...

@lilisako
Copy link

lilisako commented May 11, 2021

@radarhere @julienguegan Could I take this issue? This seems interesting.

@radarhere
Copy link
Member

@lilisako yeah, go for it

@julienguegan
Copy link
Author

@radarhere Attention, I have been using Pillow: 8.1.2 and I just saw that the new version 8.2 (April) has some update concerning .gif files. I am still trying to understand if it helps my problem ...

@julienguegan
Copy link
Author

julienguegan commented May 12, 2021

I confirm it helps ! Plus https://gist.github.com/egocarib/ea022799cca8a102d14c54a22c45efe0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants