5

I follow the step at Resize GIF animation, pil/imagemagick, python to resize image using PIL and image2gif. However, I got the resized gif washed out like below:

enter image description here

How do I solve this problem?

Community
  • 1
  • 1
hllau
  • 9,879
  • 7
  • 30
  • 35
  • One of the things mentioned by the person who answered the question you reference is that s/he could not figure out a way to preserve transparency. I think that that is probably the problem, given that it is mostly the background which has this "washed out" issue. This would lead to a lack of transparency between frames, and a broken background, as shown. – Talia Sep 22 '12 at 03:13
  • A similar question at http://stackoverflow.com/questions/9128811/how-do-you-scale-an-animated-gif-image-in-pil-and-preserve-the-animation?rq=1 – hllau Sep 26 '12 at 08:13
  • 2
    Some amazing person made an updated version of images2gif.py that does a pretty good job of fixing the transparency issue (although there are still some artifacts): https://bitbucket.org/bench/images2gif.py/overview – Coconut Jun 25 '13 at 16:52

3 Answers3

1

Here is my code

from PIL import Image, ImageSequence

filename = "demo.gif"
new_width = 100
new_height = 100

with Image.open(filename) as im:
    frames = []
    for frame in ImageSequence.Iterator(im):
        frame = frame.resize((new_width, new_height))
        frames.append(frame)
    print(f"length of freames {len(frames)}")
    frames[0].save('resized_image.gif', save_all=True, append_images=frames[1:])

Manivannan Murugavel
  • 1,476
  • 17
  • 14
0

I have not tried this, but this suggests that the way to maintain transparency in GIF images with PIL when saving is:

im = Image.open(...)
transparency = im.info["transparency"]
...
out.save("out.gif", transparency=transparency)
Talia
  • 1,400
  • 2
  • 10
  • 33
  • Thanks, but it does not seem to work, as the `.save` method is not used at all. `images2gif.writeGif()` does not expose the transparency parameter. Referring to http://stackoverflow.com/questions/9988517/resize-gif-animation-pil-imagemagick-python?rq=1 , we are using the module `images2gif` to generate the stream of GIFs. It has wrapped the conversion of images of PIL. It is not easy to understand. – hllau Sep 26 '12 at 08:06
  • I'm sorry to hear it. Unfortunately, I also have limited experience with PIL, so let's hope for someone to submit an alternative option. – Talia Sep 26 '12 at 14:39
-1

Update pillow to version 9.1.0.

cccccc
  • 1
  • 1
    Such a short answer is not high quality. Can you improve this answer by explaining why this is needed and how it would solve the problem? Is there any documentation about it that you can link to? – Stephen Ostermiller Apr 25 '22 at 15:05